模拟器上iPad的错误尺寸等级(TraitCollection)

时间:2017-08-10 18:37:23

标签: ios swift ipad size-classes uitraitcollection

我的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应该将两个尺寸类设置为常规'但是因为它发现应用程序在模拟器上运行会将尺寸类设置为常规 - 紧凑。为什么会这样?谢谢你的帮助。

0 个答案:

没有答案