【问题标题】:Storyboard Segue Transition Effects故事板 Segue 过渡效果
【发布时间】:2014-10-25 13:51:03
【问题描述】:

第一次发帖,长期观察。

我正在为我目前正在开发的应用程序使用故事板,并且需要更多的过渡,而不仅仅是前进,尤其是返回。每当我使用这个 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

我还在学习,所以如果你知道发生了什么,我很感激初学者的解释。

【问题讨论】:

    标签: ios xcode uistoryboard uistoryboardsegue


    【解决方案1】:

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

    呈现一个视图控制器:

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

    【讨论】:

    • 我做到了,这就是它向我吐口水的原因。 “SlideLeftSegue”没有可见的@interface 声明选择器“dismissViewControllerAnimated:completion:”
    • 仅供参考,当它尝试使用 SlideLeftSegue 在屏幕之间移动而崩溃时,它会显示“线程 1:EXC_BAD_ACCESS (code=EXC_I386_GPFLT)”
    • 我的理解是,您试图通过按下某种按钮来表示视图。在情节提要中,为什么不在源视图控制器中设置一个按钮,然后使用 Command-drag 将按钮连接到目标视图。之后,要返回到您的源 VC,请使用上面的代码。
    • 是的,假设我有 VC1 和 VC2。在 VC1 上,我有一个按钮,我用命令拖动到 VC2,并且 segue 是 push。在 VC2 上,我有一个按钮,我用命令拖动到 VC1 并将 segue 设置为自定义,SlideLeftSegue。我不确定我做错了什么,因为这个左转对我不起作用。
    • 好的,试试这个:取消第二个segue,将segue 1中的“push”改为“modal”。我马上发送一个示例项目。
    猜你喜欢
    • 1970-01-01
    • 2012-09-01
    • 2014-11-13
    • 2012-05-12
    • 1970-01-01
    • 2013-06-30
    • 1970-01-01
    • 2023-03-14
    • 1970-01-01
    相关资源
    最近更新 更多