为按钮设置延迟动画 - iPhone
我试图让按钮移动到一个坐标,暂停,移动到另一个坐标,暂停,然后再次移动。然后该过程应该无限重复。我现在所拥有的只是迈出了最后一步。
这就是我到目前为止所拥有的(“mover”是 UIButton 名称):
- (void) firstAnimation {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[UIView setAnimationDelay:5];
[UIView setAnimationRepeatCount:-1];
[UIView setAnimationRepeatAutoreverses:NO];
CGPoint pos = mover.center;
pos.y = 200.f;
pos.x = 169.f;
mover.center = pos;
[NSTimer timerWithTimeInterval:1.0 target:self selector:@selector(firstAnimation:) userInfo:nil repeats:NO];
pos.y = 100.f;
pos.x = 179.f;
mover.center = pos;
[NSTimer timerWithTimeInterval:1.0 target:self selector:@selector(firstAnimation:) userInfo:nil repeats:NO];
pos.y = 160.f;
pos.x = 129.f;
mover.center = pos;
[UIView commitAnimations];
}
感谢您的帮助
I'm trying to have a button move to a co-ordinates, pause, move to another co-orinates, pause, then move again. the process should then repeat infinitely. what I have right now just moves the last step.
this is what I have so far ('mover' is the UIButton name):
- (void) firstAnimation {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[UIView setAnimationDelay:5];
[UIView setAnimationRepeatCount:-1];
[UIView setAnimationRepeatAutoreverses:NO];
CGPoint pos = mover.center;
pos.y = 200.f;
pos.x = 169.f;
mover.center = pos;
[NSTimer timerWithTimeInterval:1.0 target:self selector:@selector(firstAnimation:) userInfo:nil repeats:NO];
pos.y = 100.f;
pos.x = 179.f;
mover.center = pos;
[NSTimer timerWithTimeInterval:1.0 target:self selector:@selector(firstAnimation:) userInfo:nil repeats:NO];
pos.y = 160.f;
pos.x = 129.f;
mover.center = pos;
[UIView commitAnimations];
}
thanks for any help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您不需要使用计时器,只需将动画委托设置为 self 并实现animationfinished 方法即可。
在这里查看我的答案:
无限循环的动画
You don't need to use timers, just set the animation delegate to self and implement the animationfinished method.
See my answer here:
animations on infinite loop
如果您专门针对 iOS4 进行发布,我强烈建议您使用块和以下方法:
请注意,在完成块中您也可以提示另一个动画。事实上,您可以将三个动画块存储为块变量,然后将它们简单地传递给上述方法,依次执行,直到第三个动画块完成。然后重新启动该过程即可!
积木是你的朋友。
If you're shipping for iOS4 exclusively, I thoroughly recommend using blocks and the following method:
Note that in the completion block you can just as well cue up another animation. In fact, you could store the three animation blocks as block variables and then simply pass them in to the above method to be executed, one after another, until the third completes. Then just restart the process!
Blocks are your friends.
您更适合使用 CoreAnimation 关键帧 并将
repeatCount = HUGE_VALF
设置为永远循环You would be better suited to use CoreAnimation keyframes and setting
repeatCount = HUGE_VALF
to loop forever