UIView动画以错误的属性值开头

时间:2011-09-08 14:18:26

标签: ios cocoa-touch animation uiview

您好我在我的iPhone应用程序中为UIView编码动画时遇到了一些问题。我更新了frame属性后,我正在尝试为UIView的帧设置动画。这是代码。

//old frame values are: 0, 0, 15, 37

//set the frame for hiding the arrow
[arrow setFrame:CGRectMake(-15, 100, 15, 37)];

//Create an animation to let the arrow slide in the view.
[UIView beginAnimations:@"SlideInArrow" context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationBeginsFromCurrentState:true];
[UIView setAnimationDuration:1.0];
[symbolArrow setFrame:CGRectMake(0, 100, 18, 37)];
[UIView commitAnimations];

这段代码是我写的方法的一部分。当用户按下按钮时它将被触发。我建议,UI不会将新帧值更新到对象。相反,动画使用旧值。为什么会这样?有没有办法让视图或动画获得新的帧值?

2 个答案:

答案 0 :(得分:1)

您正在设置animationBeginsFromCurrentState:,它会根据视图当前在屏幕上的位置明确告知系统动画。此时,框架仍处于{0,0},因为运行循环尚未完成,因此之前的setFrame:个事务都没有应用。首先,取出这条线,这可能会自行解决。如果没有,还有其他方法可以按照您描述的方式设置fromValue

然而,基本流程很奇怪。如果代码符合您的建议,则屏幕显示在{0,0}的屏幕上,您将使其消失并重新滑动。这真的是你想要的动画,还是有更多的动画你已经遗漏了?你想要实现的全部效果是什么?

请注意,您在一个案例中有arrow而在另一个案例中有symbolArrow,我认为这是一个拼写错误,但如果这些是不同的对象肯定会有问题。

答案 1 :(得分:0)

替换此行

     [symbolArrow setFrame:CGRectMake(0, 100, 18, 37)];

     [arrow setFrame:CGRectMake(0, 100, 18, 37)];

以及

删除此行

   [UIView setAnimationBeginsFromCurrentState:true];