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

2020-01-10  本文已影响0人  guoguojianshu

监听键盘的状态

//键盘将要出现的时候
 [[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);
    }];
}
上一篇 下一篇

猜你喜欢

热点阅读