我已经计算出在纸张上的位置和偏移。我已经写代码和调试,我得到预期的结果。然而在iPhone模拟器事情是重叠的按约15个像素。

要与我的调试下去了,我需要知道哪儿UI对象是在屏幕上。

相关的弹出搜索键盘和调整大小静态之间的UISearchBar一个UITableView和动态添加UITabBar(表视图被嵌入到标签中的一个)。不,我真的不希望使用任何硬编码值由于旋转和不同的屏幕尺寸。

我怎样才能找到呢?

- (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;
}

...代码以防万一有明显是错误我看不到了......

有帮助吗?

解决方案

您最好的选择可能是的UIView的convertPoint:toView:。找出给定视图的位置,使用:

CGPoint myPoint = [myView convertPoint:CGPointMake(0, 0) toView:((YourAppDelegate *)[[UIApplication sharedApplication] delegate]).window];
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top