1

我的 UIViewController 中有以下代码:

override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
    super.traitCollectionDidChange(previousTraitCollection)

    let horizontalSizeClass = traitCollection.horizontalSizeClass
    let verticalSizeClass = traitCollection.verticalSizeClass

    if horizontalSizeClass == .regular && verticalSizeClass == .regular {
        setConstraintsForiPad()
    } else if verticalSizeClass == .compact {
        setConstraintsForLandscape()
    } else if horizontalSizeClass == .compact && verticalSizeClass == .regular {
        setConstraintsForPortrait()
    }
}

我想通过这种方法检测 iPad - 我已经读过 iPad 应该将两个尺寸类都设置为“常规”,但事实证明,在模拟器上运行的应用程序分别将尺寸类设置为常规紧凑型。为什么呢?感谢帮助。

4

0 回答 0