I'm trying to get my ViewController to slide from Left to Right at the same speed as the standard PushViewConrtoller, I'm not using a NavBar and don't want to use Modal, is there a simple way to do this, I've seen a lot of variations on different threads, but none of them work correctly!
I'm using a Navigation Controller with the following code for my Push right...
- (IBAction)launch1990:(id)sender {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"1990Storyboard" bundle:nil];
UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"1990"];
[self.navigationController pushViewController:vc animated:YES];
}
UIStroryBoard when you push view controllers, or segues, it doesn't let you customize too much. What I ended up doing was override the perform method and used QuartzCore Animations to customize our transitions. I subclassed UIStoryBoardSegue and overwrote the perform function.
Below to customize for Push or Pop then for Segues. (For segues remember to change the class to the custom class in IB).
To do it from a normal pop or push (this does cross fade animation, adjust it for yours):
#import <QuartzCore/QuartzCore.h>
- (IBAction)launch1990:(id)sender {
CATransition* transition = [CATransition animation];
transition.duration = .45;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionFade;
[self.navigationController.view.layer addAnimation:transition forKey:kCATransition];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"1990Storyboard" bundle:nil];
UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"1990"];
[self.navigationController pushViewController:vc animated:NO];
}
To do it from segue:
//ZHCustomSegue.h
#import <Foundation/Foundation.h>
@interface ZHCustomSegue : UIStoryboardSegue
@end
// ZHCustomSegue.m
#import "ZHCustomSegue.h"
#import "QuartzCore/QuartzCore.h"
@implementation ZHCustomSegue
-(void)perform {
UIViewController *sourceViewController = (UIViewController*)[self sourceViewController];
UIViewController *destinationController = (UIViewController*)[self destinationViewController];
CATransition* transition = [CATransition animation];
transition.duration = .45;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionFade; //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