iPhone:检测UIImageView图像序列动画结束的最佳方法 [英] iPhone : Best way to detect the end of UIImageView image sequence animation

查看:230
本文介绍了iPhone:检测UIImageView图像序列动画结束的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们知道 UIImageView 对图像序列动画有非常好的支持。我们可以轻松创建一个UIImage对象数组,设置 animationImages 属性,配置动画持续时间,重复计数等,然后激发。但似乎没有办法知道这个动画什么时候结束。

We know that UIImageView has a very nice support for image sequence animation. We can easily create an array of UIImage objects, set the animationImages property, configure animation duration, repeat count etc. and then just fire. But there seems to be no way to know when this animation has ended.

假设我有10个图像,然后我想运行动画(重复计数= 1)他们。当动画结束时,我想运行一些其他代码。知道动画结束的最佳方法是什么?

Say I have ten images and then I want to run an animation (repeat count = 1) with them. And when the animation is over, I want to run some other code. What is the best way to know that animation has ended?

我已经明白我可以创建一个 NSTimer 和安排它在动画持续时间后开火。但如果你需要很好的精度,你真的不能依赖计时器。

I already understand that I can create a NSTimer and schedule it to fire after animation duration. But you really cannot rely on timer if you need good precision.

所以我的问题是,有没有更好的方法来知道 UIImageView 图像序列动画已经结束而不使用计时器?

So my question is, is there any better way to know that an UIImageView image sequence animation has ended without using the timer?

代码是这样的


myImageView.animationImages = images; // images is a NSArray of UIImages
myImageView.animationDuration = 2.0;
myImageView.animationRepeatCount = 1;

[myImageView startAnimating]


推荐答案

isAnimating 属性应该在完成动画时转到。但是,这不是一个正式的财产,所以你不能对它进行观察。你可以在一个细粒度的计时器上进行轮询(比如 CADisplayLink )。

The isAnimating property on UIImageView should go to NO when it's done animating. It's not a formal property, though, so you can't set up observation on it. You can poll it on a fine-grained timer (like CADisplayLink's).

没有动画完成代表这一点,如果这是你正在寻找的那种东西。时间可以根据图像的加载延迟等而变化,不,没有确切的方法可以准确地知道它何时完成。

There's no "animation completed" delegate for this, if that's the sort of thing you're looking for. The timing can be variable based on loading delay of the images, etc, and no, there's no sure-fire way to know precisely when it's done.

图像动画的东西在UIImageView上是一个方便,而不是重量级足以做严肃的动画工作。如果您需要那种精度,请考虑自己滚动。

The image animation stuff on UIImageView is a convenience, and not heavyweight enough to do serious animation work with. Consider rolling your own if you need that kind of precision.

这篇关于iPhone:检测UIImageView图像序列动画结束的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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