CATransition Problem

Discussion in 'iOS Programming' started by jacksongan, May 5, 2010.

  1. jacksongan macrumors member

    Joined:
    Aug 31, 2009
    #1
    Hey guys, here is my code


    Code:
    	CATransition *transition = [CATransition animation];
    	transition.duration = 1.5;
    	transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    	transition.type = kCATransitionFade;
    	transitioning = YES;
    	transition.delegate = self;
    	[containerView.layer addAnimation:transition forKey:nil];
    	
    	view1.hidden = YES;
    	view2.hidden = NO;
    
            CATransition *transition1 = [CATransition animation];
    	transition1.duration = 0.5;
    	transition1.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    	transition1.type = kCATransitionFade;
    	transitioning = YES;
    	transition1.delegate = self;
    	[containerView.layer addAnimation:transition1 forKey:nil];
    	
    	view2.hidden = YES;
    	view3.hidden = NO;
    The problem with this code is that the transition performed is the 2nd one. ie. transition1. When i click the animate button, the view jump from view1 to view3, skipping the first transition.

    Please help. Thanks!
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    I'm pretty sure you need to let the first animation block complete then request the next one...
     
  3. jacksongan thread starter macrumors member

    Joined:
    Aug 31, 2009
  4. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #4
    I just did. I would expect that you would no go to the documentation and look for methods that are called when an animation block completes. Anything short of that is just laziness.

    So, which documents did you read and what did you discover? I would suggest looking at CATransitions superclass and the obvious delegate methods.
     
  5. jacksongan thread starter macrumors member

    Joined:
    Aug 31, 2009
    #5
    well, this is actually part of the Viewtransition sample code from the developer page, with some modifications of course. I dun want to keep pressing button to call for next transition, ie. press once, view1 to view2, press twice, view2 to view3, i jus wana press once to show transition from view1 to view2 followed by view3. I jus cant figure out.
     
  6. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #6
    And to do that you will have to use the delegate method I pointed you towards to wait for the end of each transition before starting the next one. This is all the help I will give you: programming is about figuring out solutions for yourself, about using the documentation and about trying things. It's not about copy and pasting code that you ask for as "sample code" and then thinking you know what you are doing or claiming you wrote it yourself.

    Go, read, try stuff and actually learn.
     
  7. jacksongan thread starter macrumors member

    Joined:
    Aug 31, 2009

Share This Page