我正在尝试为xs max定制设计。之前我只是通过检查main.bound.screen.height来识别设备,根据此站点,对于xs max:
https://www.paintcodeapp.com/news/ultimate-guide-to-iphone-resolutions
,应该返回896.0,对吗?
xcode 10.0xs max模拟器返回812.0作为屏幕高度(xr也一样,它应该有相同的屏幕点)。知道怎么解决这个问题吗?
enum IPhone: String {
case SE, normal, plus, X, XSMax
init?(height: CGFloat) {
switch height {
case 568: self = .SE
case 667: self = .normal
case 736: self = .plus
case 812: self = .X
case 896: self = .XSMax
default:
return nil
}
}
}
struct Design {
static var iPhone = IPhone(height: UIScreen.main.bounds.height)!
}
在视图控制器的viewdidLoad()中:
print("screen height: \(UIScreen.main.bounds.height), iPhone: \(Design.iPhone.rawValue)")