Picker View not appearing on 1st attempt of button click

被刻印的时光 ゝ 提交于 2019-12-08 21:59:26

The answer from @Padavan should work, but if you want fading effect "in animation", hidden property does not do the job. You have to use UIView.alpha property instead. Here is my sample code for that.

- (void) viewDidLoad {
       [super viewDidLoad];

       /////////////////////////////////////////////////
       //    ... Initialize your month picker here    //
       /////////////////////////////////////////////////

       monthPicker.alpha = 0;    
       [self.view addSubview:monthPicker];    
}

- (void)buttonPressed:(id)sender
{
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.3];
    CGAffineTransform transform = CGAffineTransformMakeTranslation(0, 200);
    monthPicker.transform = transform;
    monthPicker.alpha = monthPicker.alpha * (-1) + 1;
    [UIView commitAnimations];  
}

Are monthPicker initially hidden? When method called first time. If no - it hides and you can't see it. Maybe you need set monthPicker.hidden=YES in init method.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!