views:

64

answers:

1

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 animations has ended.

Say I have 10 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?

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

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

The code is something like this

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

[myImageView startAnimating]
+2  A: 

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.

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.

quixoto
ya, i also think that eventually i need to handle this on my own. just wanted to be sure that im not missing anything and there is no alternate way.
taskinoor
Not sure what you mean by "formal property". It's definitely a property, but UIImageView probably doesn't call the setter (I suspect there isn't one).
tc.