新的iOS 13模态演示:演示控制器不会向下移动

时间:2019-10-07 22:19:12

标签: ios swift user-interface uiviewcontroller ios13

在iOS 13中以模态方式呈现UIViewControllers时,我的行为很怪异。我在iOS 13上所见过的新呈现方式看起来像这样:

当前视图控制器出现在当前视图控制器的后面。它还向下移动以模仿“堆栈”

The presenting view controller appears behind the presented view controller. It is also shifted down to mimic a "stack"

与此同时,通过我的应用程序显示视图控制器时,我不断得到这种效果:

呈现新的视图控制器时呈现的视图控制器完全不动

The presenting view controller doesn't move at all when presenting a new view controller

我使用以下代码介绍此视图控制器:

let controller = storyboard?.instantiateViewController(withIdentifier: "tutorial") as! TutorialController
controller.modalPresentationStyle = .pageSheet
controller.modalTransitionStyle = .coverVertical
present(controller, animated: true, completion: nil)

这是我的问题: 我想知道为什么会这样,是否有办法以普通的iOS 13样式呈现视图控制器(呈现的视图控制器向后移动)。

谢谢!

6 个答案:

答案 0 :(得分:1)

如果没有UINavigationController,我认为可以使用vc.modalPresentationStyle = .fullScreen来解决此问题,否则可以按以下方式使用这些代码:

let navigationController = UINavigationController(rootViewController: vc) 
navigationController.modalPresentationStyle = .fullScreen 
present(vc, animated: true)

因为使用iOS 13,这是一项新功能,Apple已将视图控制器的默认演示样式从iOS 12中的全屏模式更改为模式表。

答案 1 :(得分:1)

以编程方式:

let vc = UIViewController()
vc.modalPresentationStyle = .fullScreen //or .overFullScreen for transparency
self.present(vc, animated: true, completion: nil)

从情节提要中:

enter image description here

就是这样。完全不需要使用根控制器或窗口。

供参考,请访问this article

答案 2 :(得分:0)

原来的问题是我的视图控制器层次结构。通过将呈现视图控制器设置为我的应用程序的根视图控制器,我能够解决此问题。首先,我通过调用

将后台控制器设置为根视图控制器
window.rootViewController = self

然后使用我之前的代码

let controller = storyboard?.instantiateViewController(withIdentifier: "tutorial") as! TutorialController
controller.modalPresentationStyle = .pageSheet
controller.modalTransitionStyle = .coverVertical
present(controller, animated: true, completion: nil)

我介绍了视图控制器。感谢所有尝试提供帮助的人!

答案 3 :(得分:0)

我们可以在检查器工具栏中进行更改。要实现这一目标,请转到Inspector Tollbar的第五部分,然后将Presentation字段更改为Full Screen。

答案 4 :(得分:0)

iOS13:假设您有3个视图控制器:FirstVC,SecondVC,ThirdVC

FirstVC为SecondVC提供以下代码:

let secondVC = SecondVC()
secondVC.modalPresentationStyle = .fullScreen
firstVC.present(secondVC, animated: true, completion: nil)

SecondVC为ThirdVC提供以下代码:

let thirdVC = ThirdVC()
secondVC.present(thirdVC, animated: true, completion: nil)

将secondVC的modalPresentationStyle更改为.currentContext可解决此问题。

答案 5 :(得分:-1)

这应该是您需要设置的唯一属性

presentedViewController.modalPresentationStyle = .automatic

详细信息 https://developer.apple.com/videos/play/wwdc2019/224/