检测iPhone 2X的iPhone应用程序按钮
答
您可以检测通过注册的变化通知_UIClassicApplicationWillChangeZoomNotificationName
,然后使用或多或少的@magma在他的回答中概述的方法处理比例变化。 _UIClassicApplicationWillChangeZoomNotificationName
会告诉您何时使用“2x”/“1x”按钮来更改比例。
答
检查scale
属性:
[[UIScreen mainScreen] scale]
这里有一个方便的功能:
+(BOOL) screenIs2xResolution {
return 2.0 == [MyDeviceClass mainScreenScale];
}
+(CGFloat) mainScreenScale {
CGFloat scale = 1.0;
UIScreen* screen = [UIScreen mainScreen];
if ([UIScreen instancesRespondToSelector:@selector(scale)]) {
scale = [screen scale];
}
return scale;
}
答
既然你不能注册为_UIClassicApplicationWillChangeZoomNotificationName
,这似乎是一个内部恒定的,我所做的是:
注册的任何通知:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeZoom:) name:nil object:nil];
再检查相应的值:
- (void)changeZoom:(NSNotification*)notification
{
if ([[notification name] isEqualToString:@"_UIClassicApplicationWillChangeZoomNotificationName"])
{
NSLog(@"Zoom changed to %@", [[[notification userInfo] objectForKey:@"_UIClassicIsZoomedUserInfoKeyName"] boolValue] == 0 ? @"1x" : @"2x");
}
}
[在兼容模式下检测在iPad上运行的iPhone应用程序]的可能重复(http://stackoverflow.com/questions/3242620/detecting-iphone-app-running-on-ipad-in-comp可用性模式) – 2011-05-25 23:35:15
@Josh,它是相关的,但不是重复的。认识到您的iPhone应用程序正在iPad上运行,并且检测它是以1x还是2x运行,这是两码事。虽然良好的联系;您当然想要了解在采取相应措施之前,2x刻度是否与iPhone4视网膜显示屏或iPad 2x模式相关联。 – magma 2011-05-26 00:35:50