禁用iOS 13中呈现的视图控制器的交互式解雇 [英] Disable the interactive dismissal of presented view controller in iOS 13

查看:302
本文介绍了禁用iOS 13中呈现的视图控制器的交互式解雇的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

iOS 13 引入了一种新设计的modalPresentationStyle .pageSheet(及其同级.formSheet),用于以模态呈现的视图控制器…

iOS 13 introduces a new design of modalPresentationStyle .pageSheet (and its sibling .formSheet) for modally presented view controllers…

...我们可以通过将显示的视图控制器向下滑动(交互式解雇)来解雇这些工作表.尽管新的拉动关闭"功能非常有用,但可能并不总是希望如此.

…and we can dismiss these sheets by sliding the presented view controller down (interactive dismissal). Although the new "pull-to-dismiss" feature is pretty useful, it may not always be desirable.

问题:我们如何关闭交互式解雇功能? -请记住,我们保持演示文稿样式不变.

THE QUESTION: How can we turn the interactive dismissal off? - Bear in mind we keep the presentation style the same.

推荐答案

选项1:

viewController.isModalInPresentation = true

(禁用互动式.pageSheet的解雇行为是这样的.)

(Disabled interactive .pageSheet dismissal acts like this.)

  • 自iOS 13起,UIViewController包含一个名为isModalInPresentation的新属性,必须将其设置为true才能防止交互式解雇.
  • 它基本上会忽略视图控制器范围之外的事件.如果您不仅使用自动样式,还使用.popover等演示样式
  • ,请记住这一点.
  • 此属性默认为false.
  • Since the iOS 13, UIViewController contains a new property called isModalInPresentation which must be set to true to prevent the interactive dismissal.
  • It basically ignores events outside the view controller's bounds. Bear that in mind if you are using not only the automatic style but also presentation styles like .popover etc.
  • This property is false by default.

摘录自官方文档 :如果为true,则UIKit会忽略视图控制器范围之外的事件,并防止在视图控制器出现在屏幕上时对其进行交互式关闭.

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的新方法.
  • 仅当未以编程方式关闭显示的视图控制器并且其isModalInPresentation属性设置为false时,才调用此方法.
    • Since the iOS 13, UIAdaptivePresentationControllerDelegate contains a new method called presentationControllerShouldDismiss.
    • This method is called only if the presented view controller is not dismissed programmatically and its isModalInPresentation property is set to false.
    • 提示:不要忘记分配presentationController的委托.

      Tip: Don't forget to assign presentationController's delegate.

      这篇关于禁用iOS 13中呈现的视图控制器的交互式解雇的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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