I'm using storyboard to create my new iPad project. I want use the custom modal segue to have better transitions between views. My question is how do I use the custom modal and is there any tutorials out there that show using custom modal segues?
Asked
Active
Viewed 2.3k times
3 Answers
5
This custom seque pops back to the root of a navigation stack. Use a normal pop instead of "popToViewController" if you want to go back one level. I just love the name of this method.
header:
#import <UIKit/UIKit.h>
@interface FlipTopPopToRoot : UIStoryboardSegue
@end
implementation:
#import "FlipTopPopToRoot.h"
@implementation FlipTopPopToRoot
- (void) perform {
UIViewController *src = (UIViewController *) self.sourceViewController;
[UIView transitionWithView:src.navigationController.view duration:0.5
options:UIViewAnimationOptionTransitionFlipFromTop
animations:^{
[src.navigationController popToViewController:[src.navigationController.viewControllers objectAtIndex:0] animated:NO];;
}
completion:NULL];
}
@end

T.J.
- 3,942
- 2
- 32
- 40
2
I was looking for something similar and found the current answer a bit misleading. The current tutorial presented by TJ is performing a customized segue within a navigation controller. If you are looking for a modal segue I believe you need to call instead:
[self.sourceViewController presentModalViewController:self.destinationViewController animated:NO];
and change the options of your animation.
More can be found on this post I wrote: link.
1
I find this to be the easiest method rather than writing mounds of code to just slide a frame.
Here's the custom segue
- (void) perform {
UIView *oldView = ((UIViewController *)self.sourceViewController).view;
UIView *newView = ((UIViewController *)self.destinationViewController).view;
[oldView.window insertSubview:newView aboveSubview:oldView];
float offsetY = newView.center.y - oldView.center.y ;
//NSLog(@"old y = %f, new y = %f , offsetY = %f", oldView.center.y, newView.center.y, offsetY);
// assuming newView and oldView both sized to fill screen,
// position newView just to the right of oldView
newView.center = CGPointMake(oldView.center.x + oldView.frame.size.width, oldView.center.y + offsetY);
//NSLog(@"newView center x = %f y = %f", newView.center.x, newView.center.y);
// slide newView over oldView, then remove oldView
[UIView animateWithDuration:0.3
animations:^{ newView.center = CGPointMake(oldView.center.x, oldView.center.y + offsetY);}
completion:^(BOOL finished){ [oldView removeFromSuperview]; }];
}
Hope this helps!

marzapower
- 5,531
- 7
- 38
- 76

Nick Turner
- 927
- 1
- 11
- 21
-
2I have used code similar to this in a project I am making, how do you return to the original view that the new view replaces. – user1282180 Nov 24 '12 at 13:13