美文网首页
监听键盘的位置,防止内容被遮挡

监听键盘的位置,防止内容被遮挡

作者: guoguojianshu | 来源:发表于2020-01-10 08:41 被阅读0次

监听键盘的状态

//键盘将要出现的时候
 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(QiuTanTiYuDidClickKeyboard:) name:UIKeyboardWillShowNotification object:nil];
//键盘将要消失的时候
 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(QiuTanTiYuDidKeyboadrDisappear:) name:UIKeyboardWillHideNotification object:nil];

对监听到状态的改变,进行改变被遮挡控件的frame

-(void)QiuTanTiYuDidClickKeyboard:(NSNotification *)sender{
 CGRect keyboardRect = [sender.userInfo[@"UIKeyboardFrameEndUserInfoKey"] CGRectValue];
    [self.QiuTanTiYuBottomView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(-keyboardRect.size.height);
    }];
}
-(void)QiuTanTiYuDidKeyboadrDisappear:(NSNotification *)sender{
    [self.QiuTanTiYuBottomView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(-XFoot);
    }];
}

相关文章

网友评论

      本文标题:监听键盘的位置,防止内容被遮挡

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