How can I detect whether a user has an iPhone 6 Plus in standard or zoomed mode? Is this possible?
如何检测用户是否具有标准或缩放模式的iPhone 6 Plus?这可能吗?
I've tried [UIScreen mainScreen].scale
and it reports 3.0
in both cases.
我试过[UIScreen mainScreen] .scale,它在两种情况下报告3.0。
5 个解决方案
#1
11
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):
以下代码可用于获取边界,coordinateSpace,nativeScale和scale,即在iPhone 6 Plus上,nativeScale为2.608,当设备在Zoomed模式下运行时为2.88(注意它在模拟器中是不同的):
UIScreen *mainScreen = [UIScreen mainScreen];
NSLog(@"Screen bounds: %@, Screen resolution: %@, scale: %f, nativeScale: %f",
NSStringFromCGRect(mainScreen.bounds), mainScreen.coordinateSpace, mainScreen.scale, mainScreen.nativeScale);
Code for detecting iPhone 6 Plus:
检测iPhone 6 Plus的代码:
-(BOOL)iPhone6PlusDevice{
// Scale is 3 currently only for iPhone 6 Plus
if ([UIScreen mainScreen].scale > 2.9) return YES;
return NO;
}
or
要么
-(BOOL)iPhone6PlusUnZoomed{
if ([self iPhone6PlusDevice]){
if ([UIScreen mainScreen].bounds.size.height > 720.0) return YES; // Height is 736, but 667 when zoomed.
}
return NO;
}
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,要调整用户界面,请不要依赖.nativeScale,因为模拟器和实际设备会产生不同的结果。
#2
8
[UIScreen mainScreen].currentMode
reports:
[UIScreen mainScreen] .currentMode报告:
<UIScreenMode: 0x17802f240; size = 1242.000000 x 2208.000000> // STANDARD
<UIScreenMode: 0x178226be0; size = 1125.000000 x 2001.000000> // ZOOMED
#3
7
Updated macros from Paula Chavarría's answer for iOS 8 (where [UIScreen mainScreen].bounds.size
is orientation dependent):
更新了PaulaChavarría对iOS 8(其中[UIScreen mainScreen] .bounds.size取决于方向)的答案的宏:
#define IS_OS_8_OR_LATER ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
#define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
#define IS_IPHONE_5 (IS_IPHONE && (MAX([[UIScreen mainScreen] bounds].size.height, [[UIScreen mainScreen] bounds].size.width) == 568.0) && ((IS_OS_8_OR_LATER && [UIScreen mainScreen].nativeScale == [UIScreen mainScreen].scale) || !IS_OS_8_OR_LATER))
#define IS_STANDARD_IPHONE_6 (IS_IPHONE && MAX([[UIScreen mainScreen] bounds].size.height, [[UIScreen mainScreen] bounds].size.width) == 667.0 && IS_OS_8_OR_LATER && [UIScreen mainScreen].nativeScale == [UIScreen mainScreen].scale)
#define IS_ZOOMED_IPHONE_6 (IS_IPHONE && MAX([[UIScreen mainScreen] bounds].size.height, [[UIScreen mainScreen] bounds].size.width) == 568.0 && IS_OS_8_OR_LATER && [UIScreen mainScreen].nativeScale > [UIScreen mainScreen].scale)
#define IS_STANDARD_IPHONE_6_PLUS (IS_IPHONE && MAX([[UIScreen mainScreen] bounds].size.height, [[UIScreen mainScreen] bounds].size.width) == 736.0)
#define IS_ZOOMED_IPHONE_6_PLUS (IS_IPHONE && MAX([[UIScreen mainScreen] bounds].size.height, [[UIScreen mainScreen] bounds].size.width) == 667.0 && IS_OS_8_OR_LATER && [UIScreen mainScreen].nativeScale < [UIScreen mainScreen].scale)
#define IS_IPHONE_6 (IS_STANDARD_IPHONE_6 || IS_ZOOMED_IPHONE_6)
#define IS_IPHONE_6_PLUS (IS_STANDARD_IPHONE_6_PLUS || IS_ZOOMED_IPHONE_6_PLUS)
#4
7
There's a new member
有一个新成员
[[UIScreen mainScreen] nativeScale]
which should do what you want. It's only available on iOS 8, so you'll need to guard it
哪个应该做你想要的。它仅适用于iOS 8,因此您需要保护它
#5
5
These option is used to detect iPhone Devices.
这些选项用于检测iPhone设备。
#define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
#define IS_IPHONE_5 (IS_IPHONE && [[UIScreen mainScreen] bounds].size.height == 568.0)
#define IS_IPHONE_6 (IS_IPHONE && [[UIScreen mainScreen] bounds].size.height == 667.0)
#define IS_IPHONE_6PLUS (IS_IPHONE && [[UIScreen mainScreen] nativeScale] == 3.0f)
#define IS_IPHONE_6_PLUS (IS_IPHONE && [[UIScreen mainScreen] bounds].size.height == 736.0)
#define IS_RETINA ([[UIScreen mainScreen] scale] == 2.0)
#1
11
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):
以下代码可用于获取边界,coordinateSpace,nativeScale和scale,即在iPhone 6 Plus上,nativeScale为2.608,当设备在Zoomed模式下运行时为2.88(注意它在模拟器中是不同的):
UIScreen *mainScreen = [UIScreen mainScreen];
NSLog(@"Screen bounds: %@, Screen resolution: %@, scale: %f, nativeScale: %f",
NSStringFromCGRect(mainScreen.bounds), mainScreen.coordinateSpace, mainScreen.scale, mainScreen.nativeScale);
Code for detecting iPhone 6 Plus:
检测iPhone 6 Plus的代码:
-(BOOL)iPhone6PlusDevice{
// Scale is 3 currently only for iPhone 6 Plus
if ([UIScreen mainScreen].scale > 2.9) return YES;
return NO;
}
or
要么
-(BOOL)iPhone6PlusUnZoomed{
if ([self iPhone6PlusDevice]){
if ([UIScreen mainScreen].bounds.size.height > 720.0) return YES; // Height is 736, but 667 when zoomed.
}
return NO;
}
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,要调整用户界面,请不要依赖.nativeScale,因为模拟器和实际设备会产生不同的结果。
#2
8
[UIScreen mainScreen].currentMode
reports:
[UIScreen mainScreen] .currentMode报告:
<UIScreenMode: 0x17802f240; size = 1242.000000 x 2208.000000> // STANDARD
<UIScreenMode: 0x178226be0; size = 1125.000000 x 2001.000000> // ZOOMED
#3
7
Updated macros from Paula Chavarría's answer for iOS 8 (where [UIScreen mainScreen].bounds.size
is orientation dependent):
更新了PaulaChavarría对iOS 8(其中[UIScreen mainScreen] .bounds.size取决于方向)的答案的宏:
#define IS_OS_8_OR_LATER ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
#define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
#define IS_IPHONE_5 (IS_IPHONE && (MAX([[UIScreen mainScreen] bounds].size.height, [[UIScreen mainScreen] bounds].size.width) == 568.0) && ((IS_OS_8_OR_LATER && [UIScreen mainScreen].nativeScale == [UIScreen mainScreen].scale) || !IS_OS_8_OR_LATER))
#define IS_STANDARD_IPHONE_6 (IS_IPHONE && MAX([[UIScreen mainScreen] bounds].size.height, [[UIScreen mainScreen] bounds].size.width) == 667.0 && IS_OS_8_OR_LATER && [UIScreen mainScreen].nativeScale == [UIScreen mainScreen].scale)
#define IS_ZOOMED_IPHONE_6 (IS_IPHONE && MAX([[UIScreen mainScreen] bounds].size.height, [[UIScreen mainScreen] bounds].size.width) == 568.0 && IS_OS_8_OR_LATER && [UIScreen mainScreen].nativeScale > [UIScreen mainScreen].scale)
#define IS_STANDARD_IPHONE_6_PLUS (IS_IPHONE && MAX([[UIScreen mainScreen] bounds].size.height, [[UIScreen mainScreen] bounds].size.width) == 736.0)
#define IS_ZOOMED_IPHONE_6_PLUS (IS_IPHONE && MAX([[UIScreen mainScreen] bounds].size.height, [[UIScreen mainScreen] bounds].size.width) == 667.0 && IS_OS_8_OR_LATER && [UIScreen mainScreen].nativeScale < [UIScreen mainScreen].scale)
#define IS_IPHONE_6 (IS_STANDARD_IPHONE_6 || IS_ZOOMED_IPHONE_6)
#define IS_IPHONE_6_PLUS (IS_STANDARD_IPHONE_6_PLUS || IS_ZOOMED_IPHONE_6_PLUS)
#4
7
There's a new member
有一个新成员
[[UIScreen mainScreen] nativeScale]
which should do what you want. It's only available on iOS 8, so you'll need to guard it
哪个应该做你想要的。它仅适用于iOS 8,因此您需要保护它
#5
5
These option is used to detect iPhone Devices.
这些选项用于检测iPhone设备。
#define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
#define IS_IPHONE_5 (IS_IPHONE && [[UIScreen mainScreen] bounds].size.height == 568.0)
#define IS_IPHONE_6 (IS_IPHONE && [[UIScreen mainScreen] bounds].size.height == 667.0)
#define IS_IPHONE_6PLUS (IS_IPHONE && [[UIScreen mainScreen] nativeScale] == 3.0f)
#define IS_IPHONE_6_PLUS (IS_IPHONE && [[UIScreen mainScreen] bounds].size.height == 736.0)
#define IS_RETINA ([[UIScreen mainScreen] scale] == 2.0)