Challenge: sliding button with CATransition


I am not sure this is the right way or not, but I used the CATransition for this as the author hinted this on pg 378.
The additions are in bold.

Please make any corrections and/or improvements, so I can learn. Thank you.


@interface CurrentTimeViewController : UIViewController
IBOutlet UILabel *timeLabel;
IBOutlet UIButton *timeButton;


  • (IBAction)showCurrentTime:(id)sender;


Then connect the *timeButton IBOutlet to the button in the xib file.


  • (void)viewWillAppear:(BOOL)animated
    NSLog(@“CurrentTimeViewController will appear”);
    [super viewWillAppear];

CATransition *trans_but = [CATransition animation];
[trans_but setDuration:1.5];
[trans_but setType:kCATransitionPush];
[trans_but setSubtype:kCATransitionFromLeft];
[trans_but setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];
[[timeButton layer] addAnimation:trans_but forKey:@“trans_but”];

[self showCurrentTime:nil];



This looks right and I followed your approach. Seems that my button appears to be already in the final place even before the transition. Any one have any thoughts as to how to make it truly appear from the side of the screen?