tags:

views:

70

answers:

2

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 ?

A: 

Pretend the phone is still 320x480 and everything will work.

tc.
Does not make sense, why should a dev not have access to all 640x960 pixels on the screen?
Oysio
They do. Read the docs.
tc.
A: 

Perhaps you should not calculate the toolbar rect by getting from main screen size. If you are inside an UIViewController, try to get current view then set the toolbar accordingly. Here is a piece of my working code to set the toolbar just at the bottom.

CGRect mainViewBounds = self.view.bounds;

CGRect toolbarFrame = CGRectMake(CGRectGetMinX(mainViewBounds),
                             CGRectGetMinY(mainViewBounds) + CGRectGetHeight(mainViewBounds) - toolbarHeight,
                             CGRectGetWidth(mainViewBounds),
                             toolbarHeight);

[_toolbar setFrame:toolbarFrame];