Skip to content

Instantly share code, notes, and snippets.

@ljanzik
Created May 30, 2012 09:54
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save ljanzik/2835266 to your computer and use it in GitHub Desktop.
Save ljanzik/2835266 to your computer and use it in GitHub Desktop.
Implement Custom Segue To Use Own Animation
#import <UIKit/UIKit.h>
@interface MySegueWithCustomAnimation : UIStoryboardSegue
@end
#import "MySegueWithCustomAnimation.h"
@implementation MySegueWithCustomAnimation
-(void)perform{
UIViewController *destination = [self destinationViewController];
UIViewController *source = [self sourceViewController];
[destination viewWillAppear:NO];
[destination viewDidAppear:NO];
//[source retain]; only if ARC is not used
[source.view addSubview:destination.view];
CGRect original = destination.view.frame;
destination.view.frame = CGRectMake(destination.view.frame.origin.x+destination.view.frame.size.width, 0-destination.view.frame.size.height, destination.view.frame.size.width, destination.view.frame.size.height);
[UIView beginAnimations:nil context:nil];
destination.view.frame = CGRectMake(original.origin.x, original.origin.y, original.size.height, original.size.width);
[UIView commitAnimations];
[self performSelector:@selector(animationDone:) withObject:destination afterDelay:0.2f];
}
- (void)animationDone:(id)vc{
UIViewController *destination = (UIViewController*)vc;
UINavigationController *navController = [[self sourceViewController] navigationController];
[navController pushViewController:destination animated:NO];
//[[self sourceViewController] release]; only if ARC is not used
}
@end
@ebuildy
Copy link

ebuildy commented Jun 20, 2013

You forgot [[self sourceViewController] presentModalViewController:[self destinationViewController] animated:NO]; in perform method, isni't ?

@alexisbronchart
Copy link

Nope he didn't. This is a custom push segue. And by the way presentModalViewController:animated: is deprecated, if you want to make a custom modal segue use presentViewController:animated:completion: :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment