How can I animate displaying UIPickerView after pressing button?

后端 未结 6 1323
日久生厌
日久生厌 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 14:06

    You can use the following code for animating the picker view after pressing the button:

    -(IBAction)button:(id)sender
    {
    
       [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration:0.6];
        CGAffineTransform transfrom = CGAffineTransformMakeTranslation(0, 200);
        PickerView.transform = transfrom;
        PickerView.alpha = PickerView.alpha * (-1) + 1;
        [UIView commitAnimations];
    
    }
    

    Don't forget to add the following code to your viewDidLoad method

    PickerView.alpha = 0;    
    [self.view addSubview:PickerView];
    

    What it does is it makes the picker view fall from the top of the screen on 1st click and to make the picker view disappear,you can simply click the button again.From the next click the picker view just appears and vanishes..Hope it helps and works :)

提交回复
热议问题