【问题标题】:iOS: custom segue and presentViewController not working as expectediOS:自定义 segue 和 presentViewController 未按预期工作
【发布时间】:2014-06-18 18:04:07
【问题描述】:

我正在使用如下所示的自定义转场:

@implementation ModalPushSegue

- (void)perform {
    UIViewController *fromController = self.sourceViewController;
    UIViewController *toController = self.destinationViewController;
    UIView *fromView = fromController.view; 
    UIView *toView = toController.view; 

    CGPoint centerStage = toView.centerStage;
    toView.center = toView.rightStage;

    [fromView.window addSubview:toView];
    [fromController addChildViewController:toController];

    [UIView transitionWithView:toView 
                      duration:0.5 options:0
                    animations:^{
                        toView.center = centerStage;
                    }
                    completion:nil];

}

这很好,因为视图按预期从右侧滑动,并且控制器被添加到控制器层次结构中。

但稍后在添加的控制器中我会这样做:

[self presentViewController:anotherController animated:YES completion:nil];

我希望这会将新控制器的视图向上滑动到屏幕 ala modal 样式。但是发生的事情是新视图没有出现。当我稍后移除这个控制器时,它的视图会闪烁并滑出屏幕,留下黑色背景而不是原来的视图。

我已经玩了一段时间了,如果我将代码更改为

//[self presentViewController:oauthController animated:YES completion:nil];
[self.view addSubview:oauthController.view];
[self addChildViewController:oauthController];

然后视图按预期显示,尽管没有调整大小。

我的问题似乎在于 segues 设置层次结构的方式与 presentViewController 做事的方式。我已经做了很多阅读和搜索,但到目前为止还无法清楚地了解正在发生的事情。

我也尝试过在 segue 中使用 presentViewController,但不是将新视图放在旧视图上,而是屏幕变黑,然后新视图滑开。

任何帮助表示赞赏。

【问题讨论】:

    标签: ios segue


    【解决方案1】:

    在您的目标视图控制器(在情节提要中)设置情节提要 ID,然后尝试以下代码:

    AnotherController *viewC = [self.storyboard instantiateViewControllerWithIdentifier:@"AnotherController"]; 
    ModalPushSegue    *segue = [[ZHCustomSegue alloc] initWithIdentifier:@"coolSegueName" source:self destination:viewC];
    
    [segue perform];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-11-11
      • 2018-03-09
      • 2017-01-01
      • 2021-10-22
      • 2015-11-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多