iOS 13 为模态引入了 modalPresentationStyle
.pageSheet
(及其同级 .formSheet
)的新设计呈现 View Controller ...
...我们可以通过向下滑动呈现的 View Controller 来关闭这些工作表(交互式关闭)。尽管新的“拉动关闭”功能非常有用,但它可能并不总是令人满意。
问题:我们如何关闭交互式解雇? - 请记住,我们保持演示风格相同。
最佳答案
选项 1:
viewController.isModalInPresentation = true
(禁用交互 .pageSheet
像这样的解雇行为。)
- 自 iOS 13 起,
UIViewController
包含一个名为isModalInPresentation
的新属性必须设置为true
以防止交互式解雇。 - 它基本上忽略 View Controller 边界之外的事件。如果您不仅使用自动样式,还使用类似
.popover
的演示样式,请记住这一点。等等 - 此属性是
false
默认情况下。
<小时/>From the official docs: If
true
, UIKit ignores events outside the view controller's bounds and prevents the interactive dismissal of the view controller while it is onscreen.
选项 2:
func presentationControllerShouldDismiss(_ presentationController: UIPresentationController) -> Bool {
return false
}
- 自 iOS 13 起,
UIAdaptivePresentationControllerDelegate
包含一个名为presentationControllerShouldDismiss
的新方法. - 仅当所呈现的 View Controller 未以编程方式关闭且其
isModalInPresentation
时,才会调用此方法。属性设置为false
.
Tip: Don't forget to assign
presentationController
's delegate. But be aware, it is known that even just accessing thepresentationController
can cause a memory leak.
关于ios - 禁用呈现 View Controller 的交互式关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56459329/