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