zoukankan      html  css  js  c++  java
  • iOS8以后第三方键盘获取高度不对的问题

    iOS8以后苹果可以安装第三方键盘,

    通过断点我们会发现使用第三方键盘之后,

    键盘将要弹出的方法:- (void)keyBoardWillShow:(NSNotification *)notification会执行三次,

    三次的高度分别是:0:216:282。我们发现我们需要的是第三次的高度。

    我们需要注册键盘隐藏和显示的通知:

        [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyBoardDidHide:) name:UIKeyboardWillHideNotification object:nil];

        [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];

     1 #pragma mark–键盘显示事件
     2 
     3 - (void)keyboardWillShow:(NSNotification *)notification {
     4     CGFloat curkeyBoardHeight = [[[notification userInfo] objectForKey:@"UIKeyboardBoundsUserInfoKey"] CGRectValue].size.height;
     5     CGRect begin = [[[notification userInfo] objectForKey:@"UIKeyboardFrameBeginUserInfoKey"] CGRectValue];
     6     CGRect end = [[[notification userInfo] objectForKey:@"UIKeyboardFrameEndUserInfoKey"] CGRectValue];
     7     
     8     // 第三方键盘回调三次问题,监听仅执行最后一次
     9     if(begin.size.height>0 && (begin.origin.y-end.origin.y>0)){
    10         
    11         CGFloat keyBoardHeight = curkeyBoardHeight;
    12         
    13         NSLog(@"第三次:%f",keyBoardHeight);
    14         [UIView  animateWithDuration:0.05 animations:^{
    15             self.bgView.hidden = NO;
    16             self.commentToolView.y = kScreenHeight - keyBoardHeight - 44;
    17             
    18         }];
    19     }
    20 }
    21 
    22 #pragma mark–键盘隐藏事件
    23 
    24 -(void)keyBoardDidHide:(NSNotification *)notification{
    25     NSLog(@"键盘隐藏");
    26     self.bgView.hidden = YES;
    27     self.commentToolView.y = kScreenHeight;
    28 }
  • 相关阅读:
    线程运行boost库在工作(22)任务之二
    vi 帮助文档 man vi
    跳槽关系三国演义告诉我们的60条真理
    后台端口虚拟主机wdcp的相关问题以及解决方法
    格式化字符串android 格式化时间
    对象查询HQL多表联合查询的问题
    myeclipse8.6中svn插件的安装
    乱码解决方法
    Restfull风格是什么意思?
    poj3013
  • 原文地址:https://www.cnblogs.com/kfgcs/p/6390775.html
Copyright © 2011-2022 走看看