我在尝试实现 UIPickerView 在按下按钮时向上滑动的效果时遇到问题。
-(IBAction)slideUp:(id)sender{
if([sender currentTitle] == @"Select"){
[pickerView setFrame: CGRectMake(0, 415.0, 320.0, 216.0)];
[UIView beginAnimations: nil context: NULL];
[UIView setAnimationDuration: 0.5];
[UIView setAnimationCurve: UIViewAnimationCurveEaseInOut];
[pickerView setFrame: CGRectMake(0, 201.0, 320.0, 216.0)];
[UIView commitAnimations];
[slideButton setTitle:@"Done" forState:UIControlStateNormal];
} }
如您所见,代码首先检查按钮的标题是“选择”还是“完成”,如果是选择,它会在 UIPickerView 中滑动。但是,我每次构建应用程序时,第一次按下按钮时,UIPickerView 立即出现在结束位置,然后滑出视图。按钮标题不会改变。在这个初始故障之后,它工作正常。
如果您知道为什么会发生这种情况,或者可以想到一个快速解决方案,我将非常感激。
卢克