UIImageView animationRepeatCount奇怪的行为 [英] UIImageView animationRepeatCount strange behaviour

查看:684
本文介绍了UIImageView animationRepeatCount奇怪的行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有这个代码可以无限次地动画一组图像,但是只要我试图限制它动画的次数就行不通。甚至没有显示图像。

So i have this code that animates a set of images an unlimited amount of times just fine, however as soon as i try to limit the number of times it animates it simply does not work. No image is even displayed.

有效的代码:

animatedMap.animationImages = [NSArray arrayWithObjects:
                               [UIImage imageNamed:@"0.gif"],
                               [UIImage imageNamed:@"1.gif"],
                               [UIImage imageNamed:@"2.gif"],
                               [UIImage imageNamed:@"3.gif"],
                               //etc...];
animatedMap.animationDuration = 20.0f;
animatedMap.animationRepeatCount = 0;
[animatedMap startAnimating];

不起作用的代码:

animatedMap.animationImages = [NSArray arrayWithObjects:
                               [UIImage imageNamed:@"0.gif"],
                               [UIImage imageNamed:@"1.gif"],
                               [UIImage imageNamed:@"2.gif"],
                               [UIImage imageNamed:@"3.gif"],
                               //etc...];
animatedMap.animationDuration = 20.0f;
animatedMap.animationRepeatCount = 1;
[animatedMap startAnimating];

这看起来真的很奇怪吗?

This just seems like really strange behaviour?

推荐答案

我注意到了同样的行为,我的解决方案是将动画代码的开头放在不同的地方。

I noticed the same behavior, my solution was to put the start of animation code in a different place.

对我来说,它是一个View Controller,所以我把 imageView.startAnimating()放在 viewWillAppear:而不是 viewDidLoad:

For me, it was a View Controller, so I put imageView.startAnimating() in viewWillAppear: instead of viewDidLoad:.

我不是100%明白是什么问题,但可以假设动画不会触发因为通过将 animationRepeatCount 设置为1,您的一个动画会在显示视图之前发生。为了更具技术性, CATransaction :: Commit 一个动画在显示视图之前执行,而不是在视图时执行显示

I don't 100% understand what is the problem, but one can assume that the animation doesn't fire because by setting the animationRepeatCount to 1, your "one animation" happens before the view is displayed. To be more technical, the CATransaction::Commit with the one animation gets performed before the view is displayed, and not when the view is displayed.

这篇关于UIImageView animationRepeatCount奇怪的行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆