Question

I'm trying to create a custom transition between my viewControllers. I'm following this tutorial but after clicking/tapping the button nothing happens!

This is the code for CustomSegue.m

#import "CustomSegue.h"
#import "QuartzCore/QuartzCore.h"

@implementation CustomSegue

-(void)perform {
NSLog(@"ActionTest");

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

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



[sourceViewController.navigationController.view.layer addAnimation:transition forKey:kCATransition];
[sourceViewController.navigationController pushViewController:destinationController animated:NO];
}

@end

The log is logged but no transition is performed nor the viewcontroller changes. I have also changed the segue style to "custom" and class to "ZHCustomSegue"

Am I missing something?

Thank you

Was it helpful?

Solution

Change the last two lines of your segue to this:

[destinationViewController.view.layer addAnimation:transition forKey:kCATransition];
[sourceViewController presentViewController:destinationController animated:NO completion:nil]; 

You were trying to reference a navigation controller that wasn't there.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top