1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

Waiting for a UIView animation to finish

Discussion in 'Mac Programming' started by RossOliver, Apr 13, 2008.

  1. macrumors regular

    #1
    Hey,

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

    Code:
    -( 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:

    Code:
    -( 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
     
  2. macrumors newbie

    #2
    I think it'll be best to use setAnimationDidStopSelector as you said and put the time-consuming processing in a new thread.
     

Share This Page