我尝试在显示键盘时向上移动表单,我的方法是测试键盘的框架和文本字段的框架是否相交。
- (void)keyboardDidShow:(NSNotification *)notification
{
// Get the size of the keyboard.
CGRect keyboardFrame = [[[notification userInfo] objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue];
//Test whether the current frame of the text field is hidden by the keyboard
if (!CGRectIsNull(CGRectIntersection(keyboardFrame,self.activeField.frame))) {
NSLog(@"Key board frame intersects with the text field frame");
}
}
在上面的代码中,CGRectIsNull
总是返回 null。
调试语句返回有关键盘和在表单中选择的活动文本字段的这些信息:
键盘尺寸 = (width=352, height=1024) 键盘原点 = (x=-352, y=0)
关键板框架 = (-352,0,352,1024) 文本字段框架 = (200, 15, 300, 30)
每个文本字段都有相同的帧值,这意味着有问题。那么如何测试键盘是否隐藏了文本字段,以便我上下移动表单。谢谢。