UIPickerView动画故障

发布于 2024-11-28 04:09:29 字数 711 浏览 2 评论 0原文

我在尝试实现按下按钮时 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

罗罗贝儿 2024-12-05 04:09:29

我不确定你为什么会遇到这个故障,但我会在你的代码中做一些不同的事情。首先,我会用其他方法(可能在创建它之后)在远处的某个地方设置选择器视图的初始框架。然后,我将动画块之前的初始帧引用到新的 CGRect 结构,我将对其进行动画处理并重新分配。其次,如果您只想为选取器视图的 y 分量设置动画,那么我也会在动画中指定这一点。

这是我对代码的更改:

-(IBAction)slideUp:(id)sender {

if([sender currentTitle] == @"Select") {

CGRect pickerFrame = pickerView.frame;   // You set pickerView.frame in some other method.

[UIView beginAnimations: nil context: NULL];
[UIView setAnimationDuration: 0.5];
[UIView setAnimationCurve: UIViewAnimationCurveEaseInOut];

pickerFrame.origin.y = 201.0f;
pickerView.frame = pickerFrame;

[UIView commitAnimations];

[slideButton setTitle:@"Done" forState:UIControlStateNormal];

}

告诉我这是否有好处。

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:

-(IBAction)slideUp:(id)sender {

if([sender currentTitle] == @"Select") {

CGRect pickerFrame = pickerView.frame;   // You set pickerView.frame in some other method.

[UIView beginAnimations: nil context: NULL];
[UIView setAnimationDuration: 0.5];
[UIView setAnimationCurve: UIViewAnimationCurveEaseInOut];

pickerFrame.origin.y = 201.0f;
pickerView.frame = pickerFrame;

[UIView commitAnimations];

[slideButton setTitle:@"Done" forState:UIControlStateNormal];

}

Tell me if this is any good.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文