How can I animate displaying UIPickerView after pressing button?

后端 未结 6 1317
日久生厌
日久生厌 2021-02-03 13:38

I want to animate my UIPickerView after pressing the button. I already have coded my UIPickerView to be hidden on viewDidLoad and not hidden after pressing a button, but it does

6条回答
  •  离开以前
    2021-02-03 13:41

    You can use below function to perform animation of picker view.

    -(void)hideShowPickerView {
    
    if (!isPickerDisplay) {
        [UIView animateWithDuration:0.25 animations:^{
            CGRect temp = self.categoryPicker.frame;
            temp.origin.y = self.view.frame.size.height - self.categoryPicker.frame.size.height;
            self.categoryPicker.frame = temp;
        } completion:^(BOOL finished) {
            NSLog(@"picker displayed");
            isPickerDisplay = YES;
        }];
    }else {
        [UIView animateWithDuration:0.25 animations:^{
            CGRect temp = self.categoryPicker.frame;
            temp.origin.y = self.view.frame.size.height;
            self.categoryPicker.frame = temp;
        } completion:^(BOOL finished) {
            NSLog(@"picker hide");
            isPickerDisplay = NO;
        }];
    }
    

    }

    Define isPickerDisplay as BOOL and initialize this in to ViewDidLoad as given below -

    isPickerDisplay = YES;
    [self hideShowPickerView];
    

    This will manage hide and show functionality for UIPickerView.

提交回复
热议问题