故事板Segue Transition Effects

时间:2014-09-01 10:43:46

标签: ios xcode uistoryboard uistoryboardsegue

第一次发表海报,长时间观察。

我正在使用故事板作为我目前正在处理的应用程序,并且需要更多的转换而不仅仅是前进,特别是回去。每当我使用这个segue我都要通过菜单返回时,点击下一个按钮转到另一个ViewController,会使整个应用程序崩溃!

不知道发生了什么,我在实施文件

中使用了这个
#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

这是我的头文件

#import <UIKit/UIKit.h>

//  Move to the previous screen with slide animation.

@interface SlideLeftSegue : UIStoryboardSegue

@end

我还在学习,所以如果你有任何想法发生的事情,我会在初学者阶段欣赏解释。

1 个答案:

答案 0 :(得分:4)

您可以用更少的代码实现这一目标

呈现视图控制器:

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

回去:

[self dismissViewControllerAnimated:YES completion:nil];