Take the 2-minute tour ×

I was wondering if it is possible to use a CATransition within a custom Segue Transition. I created my CustomSegueTransition.m file and referenced it in my custom segue class where i want the transition to occur.

This is my code for the CustomSegueTransition.m file:

#import "CustomSegueTransition.h"
#import "QuartzCore/QuartzCore.h"

@implementation CustomSegueTransition

-(void) perform {

    // set up an animation for the transition the content
    CATransition *animation = [CATransition animation];
    [animation setDuration:0.25];
    [animation setType:kCATransitionPush];
    [animation setSubtype:kCATransitionFromRight];
    [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];

    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.25];

    [UIView commitAnimations];


It gives me no error warnings, however the transition wont perform when the button is pressed to cause the segue transition. Am i missing something in the CATransition code or is this not possible?


share|improve this question
add comment

3 Answers

up vote 1 down vote accepted


I don't have complete answer for you, but I did notice that you never call a new view thus there is no transition. I don't know whether you are shooting for a push, pop, or modal but here is the type of code you will need to add:

UIViewController *src = (UIViewController *) self.sourceViewController;
UIViewController *dst = (UIViewController *) self.destinationViewController;   
[src presentModalViewController:dst animated:YES];


    [src presentViewController:<#(UIViewController *)#> animated:<#(BOOL)#> completion:<#^(void)completion#>];

I believe there are other problems with setting up the custom animation which I don't have an answer for though I am interested in the solution.

share|improve this answer
presentModalViewController:animated: is deprecated, so presentViewController:animated:completion: should be used in this case –  user577537 Apr 3 '12 at 11:25
add comment

Not sure what you are trying, but I did find a problem.

You created a transition animation but never used it. You need to add the animation on layer of the view you want to animate.

Also you don't need to use [UIView beginAnimation]...[UIView commitAnimation] if you are going to use the lower lever CoreAnimation functions.

Use [CATransaction begin]...[CATransaction commit] if required.

share|improve this answer
add comment

Here is complete code that works

-(void)perform {

__block UIViewController *sourceViewController = (UIViewController*)[self sourceViewController];
__block UIViewController *destinationController = (UIViewController*)[self destinationViewController];                    

CATransition* transition = [CATransition animation];
transition.duration = .25;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionMoveIn; //kCATransitionMoveIn; //, kCATransitionPush, kCATransitionReveal, kCATransitionFade
transition.subtype = kCATransitionFromLeft; //kCATransitionFromLeft, kCATransitionFromRight, kCATransitionFromTop, kCATransitionFromBottom  

[sourceViewController.navigationController.view.layer addAnimation:transition

[sourceViewController.navigationController pushViewController:destinationController animated:NO];

share|improve this answer
add comment

Your Answer


