如何处理 键盘弹起中文英文高度问题

来源:互联网 发布:stc单片机论坛 编辑:程序博客网 时间:2024/05/29 18:48
我们写项目 经常会遇到 键盘弹起的情况
这种情况呢 我们可能需要把 当前的 textField调整到 合适的高度  
我处理的方式如下 

首先再全局定义一个变量 用来接受 当前可能发生调整的View 

@interface CommentViewController ()<UITextFieldDelegate,UIGestureRecognizerDelegate>{

   CGRect normalRect;  //默认高度

}




    //监控键盘

    [[NSNotificationCenterdefaultCenter]addObserver:selfselector:@selector(keyBegin:)name:UIKeyboardWillShowNotificationobject:nil ];

    

    [[NSNotificationCenterdefaultCenter]addObserver:selfselector:@selector(keyEnd:)name:UIKeyboardWillHideNotificationobject:nil ];



#pragma mark textField Methods-

- (void)keyBegin:(NSNotification *) notif{

    

    CGRect keyBoardRect = [[notif.userInfoobjectForKey:UIKeyboardFrameEndUserInfoKey]CGRectValue];

    [UIViewanimateWithDuration:.3animations:^{

        self.commentView.frame =CGRectMake(self.commentView.frame.origin.x,normalRect.origin.y- keyBoardRect.size.height,self.commentView.frame.size.width,self.commentView.frame.size.height);

    }completion:^(BOOL finished) {


    }];

}


- (void)keyEnd:(NSNotification *) notif{

    

    

    [UIViewanimateWithDuration:.3animations:^{

        self.commentView.frame =normalRect;   //恢复默认高度

    }completion:^(BOOL finished) {


    }];

    

    

}



这就是我处理 键盘弹起处理的问题
0 0