重复 UIAnimation 块,以及再次停止它的方法
我想做一个小的加载器动画来放入我的应用程序中。我之前用 CGAnimations 做过重复动画,没有任何问题,这次我采用块方法。
我正在做一个小测试,但可以重复以下代码:
- (void) startLoading {
__block int count = 0;
[UIView animateWithDuration:0.4
delay: 0.0
options: UIViewAnimationOptionRepeat
animations:^{
count++;
}
completion:^(BOOL finished){
if (count > 5)
count = 0;
NSLog(@"%d", count);
}];
}
- (void) stopLoading {
}
上面只触发完成块一次,它不会重复。
如何让块重复以便计数递增?
如果我让它工作并将我的动画放入重复块中, stopLoading:如何再次停止动画?
感谢您提供的任何帮助:)
I wanted to do a small loader animation to put in my app. I have done repeating animations before with CGAnimations without problems, this time I was going for the block approach.
I am doing a small test but can make the following code repeat:
- (void) startLoading {
__block int count = 0;
[UIView animateWithDuration:0.4
delay: 0.0
options: UIViewAnimationOptionRepeat
animations:^{
count++;
}
completion:^(BOOL finished){
if (count > 5)
count = 0;
NSLog(@"%d", count);
}];
}
- (void) stopLoading {
}
The above only fires the completion block once, it does not repeat.
How do I get the block to repeat so that count increments?
If I get this working and put my animation into the repeating block,
What goes into stopLoading: to stop the animation again?
Thanks for any help given:)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一个有限的重复动画:
这里有一个递归,所以我们不想过度,否则我们会耗尽内存,但如果我们限制我们的计数(在你的例子中是 5),我们应该没问题。
Here's a finite repeating animation:
There's a recursion here, so we don't want to go overboard or we'll run out of memory, but if we limit our count (in your example it was 5) we should be fine.