Re: UIImageView animationImages problem
Re: UIImageView animationImages problem
- Subject: Re: UIImageView animationImages problem
- From: David Duncan <email@hidden>
- Date: Tue, 9 Mar 2010 12:21:09 -0800
On Mar 8, 2010, at 2:40 PM, patrick machielse wrote:
> I'm trying to run small, full screen, 1 second long animations using the UIImageView animationImages property.
Small and fullscreen are unfortunately a contradiction in terms of iPhone. Since each frame has to be decompressed to be displayed, a fullscreen image (320x480) is 600KiB.
> The animation consists of a maximum of 9 frames, running at 18 frames per second.
And since you have up to 9 of them, your at up to 5.27MiB...
> The problem I experiece is that the animation is not smooth. Most of the time there is a short delay, after which the first frames are 'rushed' out to catch up with 'animated time'. Sometimes the animation doesn't run at all.
In part this is decoding the image (if they haven't been previously decoded). Are you using +imageNamed: or +imageWithContentsOfFile: to load the images?
> I've found that the following helps to work around this:
>
> [self preloadAnimation];
> [imageView startAnimating];
> [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1.0/FPS]];
> [imageView stopAnimating];
> [imageView startAnimating];
>
> It seems that starting animation just for a short while triggers all images to be loaded into memory before the animation starts running. Although it works for the moment, it looks quite fragile and not something I want to use in my final code.
This is basically forcing the images to be decoded. I'm not certain how fragile this is, but my intuition says that this might (in the general case) be timing dependent.
> Is there a better solution to get animationImages to work reliably? Am I doing something wrong? Can I force loading of my UIImage array 'by hand'?
The simplest way to force a UIImage to be decoded and prepared for Core Animation is to assign the UIImage to a UIImageView as its image. Keep in mind this would have to be done ahead of time and on a different run loop cycle from the one that starts your animation (as the runloop running is what commits the changes to the layer tree and kicks off the decoding process).
If you can spare the memory, you might just use +imageNamed: instead. Overall however, I generally recommend against using animationImages for fullscreen animations as the memory requirements grow rather quickly. I would generally recommend that you break your animations down into constituent pieces and do the animation in a combination of cycling images and code to move the views presenting the animation.
--
David Duncan
Apple DTS Animation and Printing
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden