Advertise Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

sdkIQ for iPhone
($4.99)

Your First iPhone App
($1.99)

iPhone Code Generator
($9.99)

Dual Matches
($0.99)

Calcuccino Programmers' Calculator
($2.99)

SDKtoday
(free)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 04-27-2009, 06:18 PM   #1 (permalink)
Registered Member
 
Join Date: Apr 2009
Location: San Jose, CA
Posts: 22
Question 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.
cmpak is offline   Reply With Quote
Old 04-28-2009, 02:49 PM   #2 (permalink)
Registered Member
 
Join Date: Apr 2009
Location: San Jose, CA
Posts: 22
Default

It seems that there is no workaround to solve the problem. So I came up with these two possible workarounds:

1. Add enough UIImageViews and display one at a time and hide the others
2. Do animation with a NSTimer myself

I think that the second one makes more sense.

Sample code can be found at
http://thefirstgood.com/tc/entry/Cha...imation-images

Last edited by cmpak; 04-28-2009 at 03:06 PM.
cmpak is offline   Reply With Quote
Reply

Bookmarks

Tags
animation, crash, timer, uiimageview

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


» Advertisements
» Stats
Members: 41,860
Threads: 49,768
Posts: 213,054
Top Poster: BrianSlick (3,138)
Welcome to our newest member, gustavo7sexton
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 06:57 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0