开发者

How to measure position of UI objects on iPhone simulator screen

开发者 https://www.devze.com 2022-12-18 18:25 出处:网络
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.

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 value开发者_开发百科s 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...


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];
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号