Most efficient way to subclass UIView to create an animated UIImageView
I need to play frame based animations. I tried the UIImageView with animationImages but it doesn't give me any control over my animation. I can't pause it, I can't mask it, I can't know the current frame etc.
So I subclassed UIView and created something I called AnimationView which takes the array of images and does the animation using an NSTimer. In the drawRect: I can then do all the masking and everything else I want.
However this method is way too slow. I can't run an animation at 30fps, maybe not even at 10fps and I am testing on a 3GS. (I am only doing masking and blending on every frame :) - and using the same images plays fine at 30fps on a UIImageView).
So, what is the most efficient way to achieve this? Is the NSTimer a bad cho开发者_如何学编程ice? Is there a better way around it?
Thanks :)
In this answer to this question Mo DeJong provides a link to a source code implementation of a class that manually animates PNG image frames. He claims to get 15 FPS for 480x320 images animating on a non-3GS iPhone.
The NSTimer
is fine. The problem is that you're touching a lot of pixels using the CPU in every frame using Quartz (the drawRect:
). What you want to do is either use OpenGL if you have to compose images using a mask or cache your images in CALayers or CGImages.
精彩评论