Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create custom modal segue in 4.2 Xcode using storyboard [closed]

Tags:

sdk

ipad

ios5

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?

like image 589
TWcode Avatar asked Nov 11 '11 17:11

TWcode


3 Answers

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
like image 95
T.J. Avatar answered Nov 12 '22 05:11

T.J.


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.

like image 2
tiguero Avatar answered Nov 12 '22 03:11

tiguero


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!

like image 1
Nick Turner Avatar answered Nov 12 '22 05:11

Nick Turner