views:

144

answers:

1

I have calculated positions and offsets on paper. I have written code and debugged that I get expected results. However on iPhone Simulator things are overlapping by about 15 pixels.

To go on with my debugging, I need to know where exactly UI objects are on the screen.

Related to popup search keyboard and resizing a UITableView between static UISearchBar and dynamically added UITabBar (table view is embedded into one of the tabs). No, I really don't want to use any hardcoded values due rotation and different screen sizes.

How can I find out this?

- (void)keyboardWasShown:(NSNotification*)aNotification
{
if (self.keyboardShown)
    return;

// Get keyboard dimensions
NSDictionary* info = [aNotification userInfo];
NSValue* aValue = [info objectForKey:UIKeyboardBoundsUserInfoKey];
CGSize kbSize = [aValue CGRectValue].size;
NSValue* endValue = [info objectForKey:UIKeyboardCenterEndUserInfoKey];
CGPoint endCenter = [endValue CGPointValue];

CGRect frame = myView.frame;
frame.size.height = endCenter.y - kbSize.height/2 - frame.origin.y;

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.2];

myView.frame = frame;

[UIView commitAnimations];

self.keyboardShown = YES;
}

...code just in case there're obvious bugs I can't see anymore...

+1  A: 

Your best bet is probably UIView's convertPoint:toView:. To find out where a given view is located, use:

CGPoint myPoint = [myView convertPoint:CGPointMake(0, 0) toView:((YourAppDelegate *)[[UIApplication sharedApplication] delegate]).window];
David Kanarek
Great tip, much better than I was looking for!
JOM