我正在尝试制作一个简单的UIImageView的动画,但无法正常工作。这是我的代码:
在我的头文件中,我已将“ light_bulb”声明为UIImageView。
NSMutableArray *bulb_off_images = [[NSMutableArray alloc] init];
for (int loop = 0; loop < 11; loop++) {
if (loop >= 10) {
[bulb_off_images addObject:[UIImage imageNamed:[NSString stringWithFormat:@"bulb_off-%d.png", loop]]];
}
else {
[bulb_off_images addObject:[UIImage imageNamed:[NSString stringWithFormat:@"bulb_off-0%d.png", loop]]];
}
}
[UIView animateWithDuration:0.5 delay:2.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
light_bulb.animationImages = bulb_off_images;
} completion:^(BOOL finished){
if (finished) {
NSLog(@"Finished !!!!!");
}
}];
该代码似乎正在运行,并且调用了完成块,但动画没有发生.....
**更新1 **
我尝试过以这种方式制作动画,但是我需要一种阻止动画重复自身的方法。我如何知道何时调用“ stopAnimating”。这是我的代码:
light_bulb.animationImages = bulb_off_images;
light_bulb.animationDuration = 0.5;
light_bulb.animationRepeatCount = 0;
[light_bulb startAnimating];
我究竟做错了什么?
关于您的原始问题,您的解决方案过于复杂。UIImageView
具有内置的动画方法。您似乎正在尝试将它们与UIView
的动画功能结合使用,这将无法完全按照您的计划进行工作。查看每个文档,并确定要使用哪些类的动画功能。
(对于图像,UIImageView
的动画方法似乎是首选的方法。)
关于第二个问题:在文档中UIImageView
,关于animationRepeatCount
状态的注释:
默认值为0,它指定无限期重复动画。
将您的设置animationRepeatCount
为1应该只播放一次动画。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句