选择单元格时显示UIPickerView

时间:2017-05-27 16:07:35

标签: ios swift uitableview uipickerview

对于我的应用,我正在使用带有动态原型单元格的tableView实现应用内设置。在内部单元格中,我显示主标题和子标题。我想要实现的是当用户点击其中一个单元格(代表特定设置)时,pickerView将从屏幕底部滑动,显示用户可以选择的选项。我已经看过很少的教程,其中这个pickerView被呈现在一个单元格中,例如它在iOS日历应用程序中,但我不需要 - 如果它从底部实际滑动,就像你将pickerView作为文本字段的inputView一样(例如textField.inputView = pickerView),一切都会好的然后单击文本字段。我感谢您提供任何帮助!提前谢谢!

1 个答案:

答案 0 :(得分:0)

You can create a custom view xib in which you can have pickerView,when user click on cell just show the custom view with animation.

viewPicker = CGRectMake(0, 490, 320, 460);

For the animation from bottom to top add below:

[UIView animateWithDuration:0.5
                      delay:0.1
                    options: UIViewAnimationCurveEaseIn
                 animations:^{
                     viewPicker.frame = CGRectMake(0, 0, 320, 460);
                 } 
                 completion:^(BOOL finished){
                 }];
[self.view addSubview:viewPicker];


For removing the view

[UIView animateWithDuration:1.5
                              delay:0.5
                            options: UIViewAnimationCurveEaseIn
                         animations:^{
    viewPicker.frame = CGRectMake(0, 490, 320, 460);
                         }
                         completion:^(BOOL finished){
                             if (finished)
                                 [viewPicker removeFromSuperview];
                         }];