ios - 禁用呈现 View Controller 的交互式关闭

标签 ios uiviewcontroller uikit modalviewcontroller ios13

iOS 13 为模态引入了 modalPresentationStyle .pageSheet(及其同级 .formSheet)的新设计呈现 View Controller ...

The new sliding modal presentation in iOS 13

...我们可以通过向下滑动呈现的 View Controller 来关闭这些工作表(交互式关闭)。尽管新的“拉动关闭”功能非常有用,但它可能并不总是令人满意。

问题:我们如何关闭交互式解雇? - 请记住,我们保持演示风格相同。

最佳答案

选项 1:

viewController.isModalInPresentation = true

Disabled interactive dismissal

(禁用交互 .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 the presentationController can cause a memory leak.

关于ios - 禁用呈现 View Controller 的交互式关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56459329/

相关文章:

ios - Obj-c 扩展在 swift 中不起作用

ios - subview 在 xcode playground 中不起作用

ios - 弹出 View Controller 是否会调用其所有属性的释放?

ios - Swift 中的 UITextStorageDirection 和 UITextLayoutDirection 枚举是什么?

ios - 无法从 plist 获取内容到 UITableview

ios - 在 iCloud 上保存游戏进度 : best solution?

ios - 在没有 Storyboard的情况下更改 View Controller

ios - 在 Swift 中 segue 之后从堆栈中移除(删除) View /viewController 的正确方法

ios - NSProgress::completedUnitCount setter 挂起

ios - 无效更新 : invalid number of rows in section