美文网首页
iOS获取键盘高度

iOS获取键盘高度

作者: Whatever永不放弃 | 来源:发表于2017-09-27 10:00 被阅读0次

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;

}

相关文章

网友评论

      本文标题:iOS获取键盘高度

      本文链接:https://www.haomeiwen.com/subject/vebyextx.html