How to change animating iamges with UIImageView
Hi,
I am trying to reuse UIImageView object instead of creating a new one. I am doing so because I found that releasing a UIImageView having animation in the middle before closing the app makes the app crash.
It's because even after stopping a timer (stopAnimating), the timer in the run loop may still point to the already released object depending on the schedule. So I found that releasing a UIImageView which uses a timer object before closing the app is not quite safe. (Correct me if I'm wrong, but that's what I found)
This description from NSTimer class reference explains why:
"The run loop removes and releases the timer, either just before the invalidate method returns or at some later point."
Anyways, how can I change animation images for the existing UIImageView which is currently animating?
stopAnimating itself is ok, but after that if I assign a new array of images, it crashes.
// This crashes the app
[self.imageView stopAnimating];
self.imageView.animationImages = newImageArr;
self.imageView.animationDuration = 0.75; // Duration in seconds
self.imageView.animationRepeatCount = 0; // zero loops forever
[self.imageView startAnimating];
Last edited by cmpak; 04-28-2009 at 03:06 PM.
|