我想在我的应用程序中实现内联UIPickerView,但是找不到实现这一目标的好代码,看起来有点复杂。
在我的iOS应用程序中是否有添加内联iOS的好示例或教程?
的答案将非常感谢
谢谢
发布于 2015-07-20 13:10:55
我喜欢本教程,它展示了如何通过静态单元格和动态单元格进行操作:http://ios-blog.co.uk/tutorials/ios-7-in-line-uidatepicker-part-1/
要旨是,制作第二个高度为0的单元格。当用户“展开”您想要的行时,翻转一个指示“选择器视图打开”的bool并重新加载该单元格,现在返回该选择器视图行的新高度。
正如有人问“这意味着什么”时,引用的是新的iOS选择器样式,而不是从屏幕底部滑动,而是显示在要编辑的字段下面。这通常是在一个表格视图中实现的,其中一个单元格是要编辑的字段,当用户触摸该字段时,该单元格会展开,显示它下面的一个选择器。这方面的一个例子是在本机设置应用程序中,通常->日期和时间,如果您自动关闭Set,您将看到当前的日期和时间。然后,如果选择该行,就会出现一个日期选择器。
发布于 2015-07-20 13:03:06
一种快速而肮脏的方法
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
CGRect frame = CGRectMake(CGRectGetMinX(cell.frame) - tableView.contentOffset.x, CGRectGetMaxY(cell.frame) - tableView.contentOffset.y, CGRectGetWidth(cell.frame), CGRectGetHeight(self.view.frame) - tableView.contentOffset.y);
UIView *snapShot = [self.view resizableSnapshotViewFromRect:frame afterScreenUpdates:NO withCapInsets:UIEdgeInsetsZero];
UIPickerView *picker = [[UIPickerView alloc]initWithFrame:frame];
picker.dataSource = self;
picker.delegate = self;
snapShot.frame = frame;
[self.view addSubview:snapShot];
picker.backgroundColor = [UIColor whiteColor];
[self.view addSubview:picker];
[self.view insertSubview:snapShot aboveSubview:picker];
[UIView animateWithDuration:2 animations:^{
snapShot.frame = CGRectOffset(snapShot.frame, 0, CGRectGetHeight(picker.frame));
}];https://stackoverflow.com/questions/31517013
复制相似问题