views:

2300

answers:

2

I have a collection of various UIImage sequences I want to animate. It turns out that using a timer and doing drawRect has some perf problems.

My next step was to investigate using UIImageView but apparently that has a memory leak if you update the array of animationImages more than once.

My next step was to look into using CALayer and CAAnimation to do it but after a quick glance at the docs they don't seem to indicate that it's meant for animating between images (note, I'm not changing position or anything else, just images).

Am I going down the right path or is there some other direction I should be investigating?

A: 

I'm not familiar with iPhone dev, but it sounds like you need a sprite for 2-d animations. A large image file that contains each frame and you only show one piece of it at a time. Like indexing a 2-d array, but you just keep track of pixel offsets for each frame.

tkotitan
+1  A: 

Do you really need to update the image array in a UIImageView more than once? I would have thought it would be best to create a new UIImageView if you need to change the animation once it has already been used?

I have heard there is a memory leak in UIImageView's array animation, but I have been using it since v2.0 and not had any significant issues with it. YMMV of course.

To set the array of frames in the first place, load up an NSMutableArray with UIImages (one for each frame) and set it into UIImageView's animationImages property (then set the animationDuration property too). Just call the startAnimating method any time you want to animate it. In normal use you shouldn't need to change the array of frames once set.

Phil Nash
I have 3 different full-screen animations that I'm working with...for now I'm going to try having 3 imageViews and just calling [bringToFront] on them when I need them.
Jonas
Although I do have another question...is there a way to determine when a UIImageView's animation has finished? I don't see any callbacks/delegates in the docs. :/
Jonas
My animations have been pretty small. Holding several full screen animations in memory at once is going to be a big hit on memory - good luck with that. If possible you should load the frames for each UIImageView as you need them.
Phil Nash