支持iOS中horizontalSizeClass=.Regular的横向定位

支持iOS中horizontalSizeClass=.Regular的横向定位,ios,swift,uikit,Ios,Swift,Uikit,我正在尝试构建一个应用程序,该应用程序支持iOS设备的纵向和横向方向,具有常规的水平尺寸类别,并且仅支持其他设备的纵向 在撰写本文时,它将是:仅适用于肖像(iPhone 6 Plus/6s Plus除外)以及iPhone 6 Plus/6s Plus和iPad的肖像和风景 这是本机邮件应用程序执行的类似行为 我尝试了以下方法: override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {

我正在尝试构建一个应用程序,该应用程序支持iOS设备的纵向和横向方向,具有常规的水平尺寸类别,并且仅支持其他设备的纵向

在撰写本文时,它将是:仅适用于肖像(iPhone 6 Plus/6s Plus除外)以及iPhone 6 Plus/6s Plus和iPad的肖像和风景

这是本机邮件应用程序执行的类似行为

我尝试了以下方法:

override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {

    return [.Portrait, .LandscapeLeft, .LandscapeRight]

}

override func shouldAutorotate() -> Bool {

    return (traitCollection.horizontalSizeClass == .Regular)

}
但是,显然在接口旋转之前调用了shouldAutororate,因此在traitCollection更新之前就调用了shouldAutororate


因此,问题是,如何实现这一点?我正试图以尽可能干净的方式完成这项工作,而无需明确引用userInterfaceIdiom、屏幕大小等。

您是否找到了解决方案?我也对这个感兴趣!很好的解决方案!我的第一个想法是“但是
traitCollection
还没有更新…”,但是纵向中的
traitCollection
displayScale
相结合确实为我们提供了所需的信息!
override var supportedInterfaceOrientations:UIInterfaceOrientationMask{

    return [.portrait, .landscapeLeft, .landscapeRight]

}

override var shouldAutorotate:Bool {

    return (traitCollection.horizontalSizeClass == .regular) || (traitCollection.displayScale > 2);

}