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

我们写项目 经常会遇到 键盘弹起的情况
这种情况呢 我们可能需要把 当前的 textField调整到 合适的高度  
我处理的方式如下 

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

@interface CommentViewController ()<UITextFieldDelegate,UIGestureRecognizerDelegate>{

    CGRect normalRect;  //默认高度

}




    //监控键盘

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

    

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



#pragma mark textField Methods-

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

    

    CGRect keyBoardRect = [[notif.userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];

    [UIView animateWithDuration:.3 animations:^{

        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{

    

    

    [UIView animateWithDuration:.3 animations:^{

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

    } completion:^(BOOL finished) {


    }];

    

    

}



这就是我处理 键盘弹起处理的问题
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值