简体   繁体   English

情节提要Segue过渡效果

[英]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! 每当我使用此命令我都需要返回菜单时,单击的下一个按钮将转到另一个ViewController,将使整个应用程序崩溃!

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. 我仍在学习,因此,如果您有任何想法,请多多指教。

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];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM