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?
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
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.
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With