Discover iPad 2x Button for iPhone App

Is there a way to detect that your iPhone application is running 2x / 1x on an iPad?

I need to be able to determine the dots per inch difference for my application.

+6
source share
3 answers

You can detect the change by registering for the _UIClassicApplicationWillChangeZoomNotificationName notification, and then handle the zoom using the more or less method described by @magma in his answer. _UIClassicApplicationWillChangeZoomNotificationName will _UIClassicApplicationWillChangeZoomNotificationName you when the 2x / 1x button is used to zoom.

0
source

Check the scale property:

 [[UIScreen mainScreen] scale] 

Here's a handy feature:

 +(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; } 

Credits: http://www.markj.net/iphone-4-2x-graphics-scale-ipad/

See also: http://struct.ca/2010/high-res-graphics-in-cocos2d/

+6
source

Since you cannot register for _UIClassicApplicationWillChangeZoomNotificationName , this seems to be the internal constant that I did:

Register for any notice:

 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeZoom:) name:nil object:nil]; 

And then check the appropriate values:

 - (void)changeZoom:(NSNotification*)notification { if ([[notification name] isEqualToString:@"_UIClassicApplicationWillChangeZoomNotificationName"]) { NSLog(@"Zoom changed to %@", [[[notification userInfo] objectForKey:@"_UIClassicIsZoomedUserInfoKeyName"] boolValue] == 0 ? @"1x" : @"2x"); } } 
+2
source

Source: https://habr.com/ru/post/889048/


All Articles