我可以通过iOS 8上的代码检测屏幕是否正常还是紧凑?
收藏

iOS 8引入了在Storyboard和Xibs中可用的新屏幕类型,我可以在代码中检测到这些类型吗?如果是,怎么办?

在这里您可以找到有关它的更多信息https://developer.apple.com/library/content/releasenotes/General/WhatsNewIniOS/Articles/iOS8.html

最佳答案

Yes you can, UIViewControllers now have a traitCollection property which has information from the device idiom, to the current size classes and more ... Furthermore you can implement the method func traitCollectionDidChange(previousTraitCollection: UITraitCollection) to get notifications when the size class (or any trait) has changed (as when the user rotates the device on an iphone). The properties of UITraitCollection that you are looking for are horizontalSizeClass and verticalSizeClass ..Here is a reference

希望能有所帮助

    公众号
    关注公众号订阅更多技术干货!