UIPickerView动画故障
我在尝试实现按下按钮时 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];
} 正如
您所看到的,代码首先检查按钮的标题是否为“Select”或“Done”,如果是选择,则它会在 UIPickerView 中滑动。但是,每次我构建应用程序时,第一次按下按钮时,UIPickerView 立即出现在结束位置,然后滑出视图。按钮标题不变。经过最初的故障后,它工作得很好。
如果您知道为什么会发生这种情况,或者能想到快速解决方案,我将非常感激。
卢克
I have a problem with an effect I am trying to implement where a UIPickerView slides up when a button is pressed.
-(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];
}
}
As you can see, the code first checks if the button's title is "Select" or "Done", and if it is select it slides in the UIPickerView. However, every time I build the application, the first time you press the button, the UIPickerView immediately appears in the end position, and then slides out of view. The button title does not change. After this initial glitch, it works fine.
If you know why this might be happening, or can think of a quick fix for it, I would really appreciate it.
Luke
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定你为什么会遇到这个故障,但我会在你的代码中做一些不同的事情。首先,我会用其他方法(可能在创建它之后)在远处的某个地方设置选择器视图的初始框架。然后,我将动画块之前的初始帧引用到新的 CGRect 结构,我将对其进行动画处理并重新分配。其次,如果您只想为选取器视图的 y 分量设置动画,那么我也会在动画中指定这一点。
这是我对代码的更改:
告诉我这是否有好处。
I'm not sure why you are getting this glitch, but there are a few things I would do differently in your code. First, I would set the initial frame of the picker view, somewhere far away, in some other method (possibly right after you create it). Then I would just reference its initial frame before the animation block to a new CGRect struct, which I will animate and reassign. Second, if you just want to animate the y-component of the picker view, then I would also specify that in the animation.
Here's my changes in your code:
Tell me if this is any good.