Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

detect iPad 2x button for iPhone app

Tags:

iphone

ipad

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

I need to be able to detect the difference in points per inch for my app.

like image 530
madmik3 Avatar asked May 25 '11 22:05

madmik3


People also ask

What is the GREY button on iPhone screen?

If there is a large circle enclosed in a grey box that appears as an overlay on your iPhone screen, your phone's AssistiveTouch feature is enabled.

How do I get rid of the control circle on my iPhone?

How to remove a control. Go to Settings > Control Center. Tap the Remove button , then tap Remove next to the app or feature that you want to remove.


2 Answers

Check the scale property:

[[UIScreen mainScreen] scale]

Here's a handy function:

+(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/

like image 196
magma Avatar answered Sep 18 '22 13:09

magma


Since you cannot register for _UIClassicApplicationWillChangeZoomNotificationName, it seems to be an internal constant, what I did is:

Register for any Notification:

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

And then check the according values:

- (void)changeZoom:(NSNotification*)notification
{
    if ([[notification name] isEqualToString:@"_UIClassicApplicationWillChangeZoomNotificationName"])
    {
        NSLog(@"Zoom changed to %@", [[[notification userInfo] objectForKey:@"_UIClassicIsZoomedUserInfoKeyName"] boolValue] == 0 ? @"1x" : @"2x");
    }
}
like image 35
jimpic Avatar answered Sep 22 '22 13:09

jimpic