PDA

View Full Version : Waiting for a UIView animation to finish




RossOliver
Apr 13, 2008, 05:41 PM
Hey,

I've been playing around with the UIShowcase example and swiped the flipImage method, modifying it to flip to a specified image:


-( void )flipToImage:( UIImage * )image
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:TRANSITION_DURATION];
[UIView setAnimationTransition:( UIViewAnimationTransitionFlipFromLeft ) forView:containerView cache:NO];

if( [secondImageView superview] )
{
firstImageView.image = image;
[secondImageView removeFromSuperview];
[containerView addSubview:firstImageView];
}
else
{
secondImageView.image = image;
[firstImageView removeFromSuperview];
[containerView addSubview:secondImageView];
}
[UIView commitAnimations];
}


I then want to do two flips in succession, so the first flip is done and when that has finished the second flip is done:


-( void )processImage:( UIImage * )image
{
[self flipToImage:image];
// CONTACT WEB SERVER WHICH TAKES A RANDOM AMOUNT OF TIME
[self flipToImage:NO_IMAGE];
}


The problem I have is that only the second flip to NO_IMAGE is happening because as soon as it is called it stops the first flip to image. Is there any way to turn of the asynchronous behaviour of the flipToImage method? Usually an outer method waits until it has finished executing a submethod...

I'm fairly sure I could create some delegate methods to respond to a setAnimationDidStopSelector message, but I want to do some processing for a random amount of time between the first and second image flip, so waiting for the first to finish flipping before I start processing is a waste of time...

Thanks for your time,

-Ross



jasamer
Apr 14, 2008, 07:25 AM
I think it'll be best to use setAnimationDidStopSelector as you said and put the time-consuming processing in a new thread.