Disable the interactive dismissal of presented view controller(禁用呈现的视图控制器的交互式解除)
问题描述
iOS 13 为模态引入了新的 modalPresentationStyle .pageSheet(及其兄弟 .formSheet)设计呈现视图控制器……
iOS 13 introduces a new design of modalPresentationStyle .pageSheet (and its sibling .formSheet) for modally presented view controllers…
...我们可以通过向下滑动呈现的视图控制器来关闭这些工作表(交互式关闭).尽管新的pull-to-dismiss"功能非常有用,但它可能并不总是可取的.
…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.
推荐答案
选项一:
viewController.isModalInPresentation = true
(禁用交互式 .pageSheet 解雇行为是这样的.)
(Disabled interactive .pageSheet dismissal acts like this.)
- 从 iOS 13 开始,
UIViewController包含一个名为isModalInPresentation的新属性,必须将其设置为true以防止交互式关闭. - 它基本上会忽略视图控制器范围之外的事件.请记住,如果您不仅使用自动样式,还使用 
.popover等表示样式. - 此属性默认为
false. 
- Since the iOS 13, 
UIViewControllercontains a new property calledisModalInPresentationwhich must be set totrueto 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 
.popoveretc. - This property is 
falseby 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, 
UIAdaptivePresentationControllerDelegatecontains a new method calledpresentationControllerShouldDismiss. - This method is called only if the presented view controller is not dismissed programmatically and its 
isModalInPresentationproperty is set tofalse. 
提示:不要忘记分配presentationController的委托.
Tip: Don't forget to assign presentationController's delegate.
这篇关于禁用呈现的视图控制器的交互式解除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:禁用呈现的视图控制器的交互式解除
				
        
 
            
        - 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
 - android 4中的android RadioButton问题 2022-01-01
 - MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
 - Android viewpager检测滑动超出范围 2022-01-01
 - Android - 拆分 Drawable 2022-01-01
 - 想使用ViewPager,无法识别android.support.*? 2022-01-01
 - 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
 - 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
 - 用 Swift 实现 UITextFieldDelegate 2022-01-01
 - Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
 
				
				
				
				