1.先监控键盘出现的事件 :
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyBoardWillShow:) name:UIKeyboardWillShowNotification object:nil];
2.在监控触发的方法里获取键盘的高度:-(void)keyBoardWillShow:(NSNotification *)notification{
NSLog(@"notification is %@ ",notification);
NSDictionary *dic=[notification userInfo];
NSValue *value=[dic objectForKey:@"UIKeyboardFrameEndUserInfoKey"];
CGRect rect=[value CGRectValue];
UIView *view=[self viewWithTag:2002];
CGFloat keyBHeight=rect.size.height;
//根据键盘高度进行判断 做一些处理 比如是否遮盖输入框等问题 计算
}
}
本文介绍了如何在iOS应用中实现键盘事件的监听,并详细解释了如何通过监听键盘弹出通知来获取键盘的高度,以便进一步处理键盘遮挡输入框等问题。

被折叠的 条评论
为什么被折叠?



