【问题标题】:Present modal view controller over modal view controller在模态视图控制器上呈现模态视图控制器
【发布时间】:2015-04-05 04:36:22
【问题描述】:

我有一个视图控制器 VC1,它从其他 VC0 以模态方式显示在全屏上。在我的故事板中,我有一个从 VC1 到 VC2 的模态转场,也全屏呈现。在我的应用程序中,我可以清楚地看到 VC2 优于 VC1 而不是 VC0,因为它们的某些部分视图是透明的。完美。

但是,我将多次重复使用 VC2,所以我不想为我的故事板中的每个控制器都设置一个 segue,所以我想以编程方式完成同样的事情。但是,当我在 VC1 中调用 presentViewController:animated:completion 来呈现 VC2 时,模态转换完成后 VC1 的视图消失了。当 VC2 关闭时,VC1 的视图会在过渡动画完成后重新出现。

如何以编程方式获得与使用情节提要转场时相同的效果?

【问题讨论】:

    标签: ios modal-dialog transition


    【解决方案1】:
    let newView = self.storyboard!.instantiateViewControllerWithIdentifier("NewViewController") as! NewViewController
    
    newView.modalPresentationStyle = UIModalPresentationStyle.OverFullScreen
    
    self.presentViewController(newView, animated: true, completion: nil)
    

    【讨论】:

      【解决方案2】:

      您只能在可见控制器上呈现,通常是rootViewController。但是当有一个模态呈现的控制器时,它会覆盖根控制器,所以你不能使用它。但是您可以在通过rootViewController.prsentedViewController 访问的模式上进行展示。这是一些代码:

      let rootVC = window?.rootViewController
      let presentingVC = (rootVC?.presentedViewController ?? rootVC)
      presentingVC?.present(myController, animated: true, completion: nil)
      

      您无需更改modalPresentationStyle

      【讨论】:

      • 这对我有用,是合理的支持答案。谢谢。
      • 为我工作!这应该被选为这个主题的最佳答案!
      • 这个答案对我有用,谢谢!
      【解决方案3】:

      您需要将显示的控制器的modalPresentationStyle 属性设置为UIModalPresentationOverFullScreen。在调用 presentViewController:animated:completion 之前设置该属性。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-06-08
        • 1970-01-01
        • 2016-02-03
        • 1970-01-01
        • 2012-12-03
        • 2012-07-24
        • 1970-01-01
        • 2011-01-15
        相关资源
        最近更新 更多