如何检测用户是否具有标准或缩放模式的iPhone 6 Plus? [英] How can I detect whether a user has an iPhone 6 Plus in standard or zoomed mode?
问题描述
如何检测用户是否拥有标准或缩放模式的iPhone 6 Plus?
这可能吗?
How can I detect whether a user has an iPhone 6 Plus in standard or zoomed mode? Is this possible?
我试过 [UIScreen mainScreen] .scale
并报告 3.0
在这两种情况下。
I've tried [UIScreen mainScreen].scale
and it reports 3.0
in both cases.
推荐答案
以下代码可用于获取 bounds
, coordinateSpace
, nativeScale
和 scale
,即在iPhone 6 Plus上 nativeScale
为2.608,当设备在Zoomed模式下运行时为2.88(注意它是在模拟器中不同):
The following code may be used to get bounds
, coordinateSpace
, nativeScale
and scale
, i.e. on an iPhone 6 Plus the nativeScale
is 2.608 and when the device in run in Zoomed Mode it is 2.88 (note that it is different in the simulator):
UIScreen *mainScreen = [UIScreen mainScreen];
NSLog(@"Screen bounds: %@, Screen resolution: %@, scale: %f, nativeScale: %f",
NSStringFromCGRect(mainScreen.bounds), mainScreen.coordinateSpace, mainScreen.scale, mainScreen.nativeScale);
检测iPhone 6 Plus的代码:
Code for detecting iPhone 6 Plus:
-(BOOL)iPhone6PlusDevice{
// Scale is 3 currently only for iPhone 6 Plus
if ([UIScreen mainScreen].scale > 2.9) return YES;
return NO;
}
或
-(BOOL)iPhone6PlusUnZoomed{
if ([self iPhone6PlusDevice]){
if ([UIScreen mainScreen].bounds.size.height > 720.0) return YES; // Height is 736, but 667 when zoomed.
}
return NO;
}
注意:如果您要检查iPhone 6 Plus,请调整用户界面然后不要依赖 .nativeScale
,因为模拟器和实际设备会给出不同的结果。
Note: If you are checking for iPhone 6 Plus, to adjust the user interface then don´t rely on .nativeScale
, because the simulator and an actual device give different results.
这篇关于如何检测用户是否具有标准或缩放模式的iPhone 6 Plus?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!