iOS获取键盘高度

来源:互联网 发布:淘宝店拍照 编辑:程序博客网 时间:2024/06/05 09:37

当你输入密码时,弹出框将屏幕下方的点击按钮挡住,就用以下方法


1)注册监听,监听键盘的弹出

[[NSNotificationCenterdefaultCenter]addObserver:self selector:@selector(handleKeyBoardNotification:) name:UIKeyboardWillShowNotification object:nil];

2)在监听的触发方法当中,使用如下代码获取键盘高度

-(void)handleKeyBoardNotification:(NSNotification *)sender {

    //获取键盘高度,关键的一句

      NSValue *value = [sender.userInfoobjectForKey:@"UIKeyboardBoundsUserInfoKey"];

      CGSize keyboardSize = [valueCGRectValue].size;

      float keyboardHeight = keyboardSize.height;

 }



原创粉丝点击