【问题标题】:Difference between 2 adaptivePresentationStyle methods of the UIPopoverPresentationControllerDelegate protocolUIPopoverPresentationControllerDelegate 协议的 2 个adaptivePresentationStyle 方法的区别
【发布时间】:2020-04-09 07:38:11
【问题描述】:

我正在使用弹出框视图控制器,我不希望弹出框覆盖全屏(iOS 13)。我试图使用:

func adaptivePresentationStyle(for controller: UIPresentationController) -> UIModalPresentationStyle {
        return .none
}

正在调用该方法,但显示的弹出框总是全屏显示,即使指定了较小的首选内容大小。经过大量时间尝试许多不同的事情后,我发现还有另一种具有 2 个参数的方法并使用它:

func adaptivePresentationStyle(for controller: UIPresentationController, traitCollection: UITraitCollection) -> UIModalPresentationStyle {
        return .none
}

使用此方法使弹出屏幕成为指定的大小。任何人都知道为什么第二个会起作用而第一个不会。我有几个其他应用程序,我使用第一个没有问题,有什么问题?!!

【问题讨论】:

    标签: ios swift uipopovercontroller uimodalpresentationstyle uipresentationcontroller


    【解决方案1】:

    由于文档:从 iOS 8.3 开始我们应该使用

    adaptivePresentationStyle(for:traitCollection:)

    处理所有特征变化。在哪里

    UITraitCollection - iOS 界面环境,由水平和垂直大小类、显示比例和用户界面习惯用法等特征定义。

    如果我们不在delegate中实现这个方法,UIKit会调用

    adaptivePresentationStyle(for:)

    方法。

    所以我猜想在您的应用程序中,您尝试使用 UITraitCollection Horizo​​ntalSizeClass、verticalSizeClass、displayScale 和 userInterfaceIdiom 属性创建一个自适应界面并访问特定的特征值。这就是为什么你应该实现 adaptivePresentationStyle(for:traitCollection:)

    【讨论】:

    • 我没有在我的应用程序中明确使用任何 UITraitCollection 特征,就像我之前所说,我在其他应用程序中使用没有 traitCollection 的方法没有问题。也许问题可能是在这个特定的应用程序中,我将方向限制为横向,这出于某种原因需要使用带有 traitCollection 参数的方法。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-06-03
    • 2013-10-15
    • 2017-11-08
    • 1970-01-01
    • 2023-04-10
    • 1970-01-01
    • 2018-08-03
    相关资源
    最近更新 更多