【问题标题】:Target iphone XR in Zoomed mode and not iphone6 with media queries以缩放模式定位 iphone XR,而不是使用媒体查询的 iphone6
【发布时间】:2020-05-29 22:21:10
【问题描述】:
我知道可以使用以下媒体查询来定位特定的 iphone 型号:
@media only screen
and (min-device-width : 375px)
and (max-device-width : 667px)
and (orientation : portrait) { /* STYLES GO HERE */ }
但是,iPhone XR 在缩放模式下的像素大小/比率与 6、7、8 型号完全相同,有谁知道一种仅针对缩放模式下的 iphone XR 的方法?
【问题讨论】:
标签:
css
ios
media-queries
【解决方案1】:
我们可以通过屏幕高度和宽度来识别设备,我这样做是为了获取高度
extension UIScreen {
var isPhone4: Bool {
return self.nativeBounds.size.height == 960;
}
var isPhone5: Bool {
return self.nativeBounds.size.height == 1136;
}
var isPhone6: Bool {
return self.nativeBounds.size.height == 1334;
}
var isPhone6Plus: Bool {
return self.nativeBounds.size.height == 2208;
}
var isPhoneX: Bool {
return self.nativeBounds.size.height == 2436;
}
var isPhoneXsMax: Bool{
return self.nativeBounds.size.height == 2688;
}
var isPhoneXR:Bool{
return self.nativeBounds.size.height == 1792;
}
}