views:

64

answers:

2

Hi all,

I wonder if anyone can help me with following. I have written a Quartz 2d ap and have used the following code to get the correct scale factor for each device :

if ([UIScreen instancesRespondToSelector:@selector(scale)])
{
        return [[UIScreen mainScreen] scale];
}
else
{
        return 1.0;
}

I then multiply all values by this scale mulitplier in my code. The problem I have is that the app does not display propertly in x2 mode on the ipad - everything is two times too big. Can anybody help me ?

Thanks,

Martin

+1  A: 

I am not sure if this is your problem, but you seem to want to test the UIScreen for the selector scale. Which it will never have. That selector works only on [UIScreen mainScreen].

if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)])
{
     return [[UIScreen mainScreen] scale];
}
else    
{
     return 1.0;
}

Although, this mistake would let you think that it would always return a scale of 1.0.

Wim Haanstra
+2  A: 

The scale factor is related to the Retina displays on the newer iPhones and iPod touches, not the 2X scaling setting on the iPad. In fact, the UIScreen scale property you are referencing does not exist on the iPad's current 3.2 OS version, only on 4.0+. On the current iPads running the OS 4.2 beta, it should always return 1.0.

The problem you are experiencing with Quartz drawing in the 2X mode must come from somewhere else. Do you do any device-specific checks for any elements in your code?

Brad Larson
Actually the problem is that the scale property is not /defined/ until 4.0, but it actually exists (as an undocumented property) in 3.2 and does something different (reports the drawing scale for non-iPad apps, basically 1.0 or 2.0 depending on the scale size of the app). So just testing the existence of the property doesn't help OP in this case, he has to check the version is 4.0 or better.
Jason Coco
Hi Brad. Thanks for your answer. There are no device specific checks in my code - I just take the value returns by the above and mulitlpy all x and y values by it. If I change the above to use responds to contentsScaleFactor it then works fine on the iPad (also in x2 mode) but stop working on the iPhone 4 - everything is half the size :(
Ohnomycoco
Jason - thank you ! That makes sense - the ipad is returning a value of two hence the fact everything is twice the size. How can I fix this ?
Ohnomycoco
@Jason - I wasn't aware of that. I may need to check my code now to make sure that I'm not making a bad assumption in a few places.
Brad Larson
@Ohnomycoco - No. You can obtain the version using `float ver = [[[UIDevice currentDevice] systemVersion] floatValue];` and then compare the value of ver against whatever OS version threshold you have.
Brad Larson
Thanks Brad - its now working ! Do I need to check for 3.2 in addition to 3.2.2 ?
Ohnomycoco
@Ohnomycoco - If checking for iPad OS versions that have the private UIScreen `scale` property, you'd want to test the range 3.2 <= ver < 4.0.
Brad Larson
Thanks Brad - so 4 and greater will return 1 - thanks
Ohnomycoco