如何在 Swift 中的当前视图之上呈现模式 [英] How to present a modal atop the current view in Swift

查看:27
本文介绍了如何在 Swift 中的当前视图之上呈现模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(Xcode6、iOS8、Swift、iPad)

(Xcode6, iOS8, Swift, iPad)

我正在尝试创建一个经典的类似 Web 的模态视图,其中对话框的外部是变灰的".为了实现这一点,我将模式视图的 backgroundColor 的 alpha 值设置为 0.5,如下所示:

I am trying to create a classic Web-like modal view, where the outside of the dialog box is "grayed-out." To accomplish this, I've set the alpha value of the backgroundColor of the view for the modal to 0.5, like so:

self.view.backgroundColor = UIColor.blackColor().colorWithAlphaComponent(0.5)

唯一的问题是当模态变成全屏时,呈现视图被移除.(参考 导航控制器上的透明模态视图).

The only problem is that when the modal becomes full-screen, the presenting view is removed. (Ref Transparent Modal View on Navigation Controller).

(对这里的概念有点恼火.为什么要删除底层视图?根据定义,模态是出现在其他内容之上.一旦底层视图被删除,它就不再是真正的模态了.它介于模态之间和推动过渡.哇哇哇......无论如何......)

(A bit irritated at the concept here. Why remove the underlying view? A modal is, by definition, to appear atop other content. Once the underlying view is removed, it's not really a modal anymore. it's somewhere between a modal and a push transition. Wa wa wa... Anyway..)

为了防止这种情况发生,我在父控制器的 viewDidLoad 方法和 Storyboard 中将 modalPresentationStyle 设置为 CurrentContext...但没有运气.

To prevent this from happening, I've set the modalPresentationStyle to CurrentContext in the viewDidLoad method of the parent controller, and in Storyboard... but no luck.

    self.modalPresentationStyle = UIModalPresentationStyle.CurrentContext
    self.navigationController.modalPresentationStyle = UIModalPresentationStyle.CurrentContext

当模态变为全屏时,如何防止当前视图被移除?

How do I prevent the presenting view from being removed when the modal becomes full screen?

tyvm.. 更多信息如下.

tyvm.. more info below.

也在情节提要中,像这样(演示:当前上下文)

Also in Storyboard, like so (Presentation: Current Context)

感谢您的帮助...文档如下:

Thx for your help... documentation below:

推荐答案

首先,删除代码中所有对模态表示样式的显式设置,并执行以下操作:

First, remove all explicit setting of modal presentation style in code and do the following:

  1. 在情节提要中将 ModalViewController 的 modalPresentation 样式设置为 Over Current context
  1. In the storyboard set the ModalViewController's modalPresentation style to Over Current context

  1. 选中 Root/Presenting ViewController - Provide ContextDefine Context 中的复选框.他们似乎甚至不受限制地工作.
  1. Check the checkboxes in the Root/Presenting ViewController - Provide Context and Define Context. They seem to be working even unchecked.

这篇关于如何在 Swift 中的当前视图之上呈现模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆