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

查看:348
本文介绍了如何在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).

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

(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..)

为了防止这种情况发生,我设置了 modalPresentationStyle 到父控制器的 viewDidLoad 方法中的 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为您提供帮助...以下文档:

Thx for your help... documentation below:

推荐答案

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

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


  1. 在故事板中设置ModalViewController的 modalPresentation 样式到过度上下文

  1. In the storyboard set the ModalViewController's modalPresentation style to Over Current context


  1. 选中复选框根/呈现ViewController - 提供上下文定义上下文
    他们似乎甚至都没有工作。

  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天全站免登陆