【发布时间】:2010-11-16 08:24:26
【问题描述】:
我正在为一堆按钮设置动画,因此它们会移动到屏幕的左侧,然后它们应该会神奇地移动到屏幕的右侧。我通过调用来做到这一点:
[NSTimer scheduledTimerWithTimeInterval:0.20 target:self selector:@selector(moveTheButtons) userInfo:nil repeats:YES];
在 viewDidLoad 中。
他们很高兴地向左移动,但随后又向右侧移动。我只是希望它们消失并重新出现在屏幕外。因为我是新来的,所以我认为因为在 commitAnimations 调用之后它不会动画。我认为问题在于 moveTheButtons 函数返回后动画实际上是“提交”,但我想不出一种优雅(或标准)的方式来解决这个问题。
如何在不设置动画的情况下将 UIButton 移出屏幕,最好还是在 moveTheButtons 函数中?
正如您可能推断的那样,我是 iPhone 上的动画新手,所以如果您发现任何其他错误,请随时给我一些指示。
-(void)moveTheButtons{
NSLog(@"moveTheButtons");
[UIView beginAnimations:@"mov-ey" context:cloudA];
[UIView setAnimationDuration: .20];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
cloudA.center = CGPointMake(cloudA.center.x-pos.x,cloudA.center.y);
[UIView commitAnimations];
if(cloudA.center.x < -100){
//I don't want to animate this bit.
cloudA.center = CGPointMake(550,cloudA.center.y);
}
//NSLog(@"cloudA.center.x %f", cloudA.center.x);
}
【问题讨论】:
标签: iphone cocoa-touch uiview core-animation