iOS获取键盘高度
(1)注册监听,监听键盘的弹出
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleKeyBoardNotification:)
name:UIKeyboardWillShowNotification
object:nil];
(2)在监听的触发方法当中,使用如下代码获取键盘高度
-(void)handleKeyBoardNotification:(NSNotification *)sender {
// 获取键盘高度,关键的一句
NSValue *value = [sender.userInfo objectForKey:@"UIKeyboardBoundsUserInfoKey"];
CGSize keyboardSize = [value CGRectValue].size;
float keyboardHeight = keyboardSize.height;
}
网友评论