简体   繁体   中英

Showing UIPickerView when cell is selected

For my app I'm implementing in-app settings using tableView with Dynamic prototype cells. Inside cell I'm showing main title and sub title. What I would like to achieve is when user clicks on one of the cells (that represents specific settings) the pickerView will slide from the bottom of the screen showing the options that user can pick. I've seen few tutorials where this pickerView is presented inside a cell as it is eg in iOS calendar app but I don't need that – all will be fine if it will slide from the bottom actually in a same way as it is when you are having pickerView as inputView for your text field (eg textField.inputView = pickerView) and click to the text field. I appreciate any help you can provide guys! Thanks in advance!

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];
                         }];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM