I read about the point/pixels bit in the apple documentation, but still things are not completely clear to me.
What I try to accomplish is placing a toolbar just above the keypad that appears when a textview is touched. The way it was working before IOS4 was by placing the toolbar at position 0,480
and then let it come up by subtracting keypad.size.y
from it's Y coordinate. In IOS4 this is still working fine as long as I'm using the 3gs simulator but as soon as I switch to the giant iphone4 simulator the toolbar won't come up with the keypad because it'll just move somewhere offscreen.
I understand there is now a scale factor involved when it comes to calculating screen coordinates and makes sense to replace the toobar's start position (0,480) by using something like
CGRect phoneRect = [Util getPhoneScreenSize];
CGSize phoneSize = phoneRect.size;
CGRect toolbarFrame = CGRectMake(0, phoneSize.height, phoneSize.width, 44);
where getPhoneScreenSize:
+(CGRect) getPhoneScreenSize
{
UIScreen *mainScreen = [UIScreen mainScreen];
CGRect bounds = [mainScreen bounds];
CGRect phoneRect = bounds;
if([[UIScreen mainScreen] respondsToSelector:NSSelectorFromString(@"scale")])
{
CGFloat scale = [mainScreen scale];
if ( scale > 0 ) {
phoneRect.origin.x *= scale;
phoneRect.origin.y *= scale;
phoneRect.size.width *= scale;
phoneRect.size.height *= scale;
}
}
return phoneRect;
}
But still the confusing part is, although I'm getting the correct resolution from getPhoneScreenSize
for the HD screen, which is 640 x 960, using these coordinates to set my toolbar just offscreen (0,960) will in fact place it way offscreen and make it not come up again.
It seems the size of the HD screen is not mapping to the drawing coordinates I need to use to place something at an exact position on that same screen.
Is the simulator going weird on me? Or am I missing something ?