我想做一个小的加载器动画来放入我的应用程序中。我之前用 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: 会再次停止动画吗?
感谢您提供的任何帮助:)
这是一个有限重复的动画:
- (void) animate: (int) count {
CGPoint origC = v.center;
void (^anim) (void) = ^{
v.center = CGPointMake(100,100);
};
void (^after) (BOOL) = ^(BOOL finished) {
v.center = origC;
if (count)
[self animate:count-1];
};
int opts = UIViewAnimationOptionAutoreverse;
[UIView animateWithDuration:1 delay:0 options:opts
animations:anim completion:after];
}
这里有一个递归,所以我们不想过度,否则我们会耗尽内存,但如果我们限制计数(在你的例子中是 5),我们应该没问题。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)