当键盘显示时,我尝试向上移动窗体,我的方法是测试键盘的框架和文本框的帧是否相交。测试键盘在显示时是否隐藏文本字段
- (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。
甲调试语句返回我的形式被选择有关键盘和有源文本字段这些信息:
键盘大小=(宽度= 352,高度= 1024) 键盘原点=(X = -352 ,Y = 0)
键板帧=(-352,0,352,1024) 文本字段帧=(200,15,300,30)
每个文本字段具有相同的帧值时,这意味着有些事情是错的。那么,如何测试键盘是否隐藏了文本字段,以便我可以上下移动表格。感谢名单。