我已经在纸上计算了位置和偏移量。我已经编写了代码并调试了我得到预期的结果。然而,在 iPhone 模拟器上,事物重叠了大约 15 个像素。
要继续调试,我需要知道 UI 对象在屏幕上的确切位置。
与弹出搜索键盘和在静态 UISearchBar 和动态添加的 UITabBar 之间调整 UITableView 的大小相关(表格视图嵌入到选项卡之一中)。不,由于旋转和不同的屏幕尺寸,我真的不想使用任何硬编码值。
我怎样才能知道这个?
- (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;
}
...代码以防万一我再也看不到明显的错误...