Jlentriken
Jlentriken

Reputation: 13

Storyboard Segue Transition Effects

First time poster, long time observer.

I am using storyboards for an app I am working on at present, and require more of a transition than just going forward, for going back in particular. Whenever i use this segue i have for going back through a menu, the next button that is clicked on to go to another ViewController, will crash the whole app!

No idea whats going on, i am using this in the implementation file

#import "SlideLeftSegue.h"

@implementation SlideLeftSegue

- (void)perform{
    UIView *sv = ((UIViewController *)self.sourceViewController).view;
    UIView *dv = ((UIViewController *)self.destinationViewController).view;

    UIWindow *window = [[[UIApplication sharedApplication] delegate] window];
    dv.center = CGPointMake(sv.center.x - sv.frame.size.width, dv.center.y);
    [window insertSubview:dv belowSubview:sv];

    [UIView animateWithDuration:0.4
                     animations:^{
                         dv.center = CGPointMake(sv.center.x,
                                                 dv.center.y);
                         sv.center = CGPointMake(sv.center.x + sv.frame.size.width,
                                                 dv.center.y);
                     }
                     completion:^(BOOL finished){
                         [[self destinationViewController]
                          dismissViewControllerAnimated:NO completion:nil];
                     }];
}

@end

This is my header file

#import <UIKit/UIKit.h>

//  Move to the previous screen with slide animation.

@interface SlideLeftSegue : UIStoryboardSegue

@end

I am still learning, so if you have any idea whats happening, id appreciate an explanation at a beginner level.

Upvotes: 1

Views: 795

Answers (1)

Kenan Karakecili
Kenan Karakecili

Reputation: 761

You can achieve that with less code

To present a view controller:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController *view = [storyboard instantiateViewControllerWithIdentifier:@"ViewID"];
view.modalTransitionStyle = UIModalTransitionStyleCoverVertical; // you can try the other 3 UIModalTransitionStyle too
[self presentViewController:view animated:YES completion:nil];

To go back:

[self dismissViewControllerAnimated:YES completion:nil];

Upvotes: 4

Related Questions