博客> 监听键盘
监听键盘
2017-12-11 19:21 评论:1 阅读:1150 vistatinchao
ios 通知 keyboard

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillChangeFrame:) name:UIKeyboardWillChangeFrameNotification object:nil];

  • (void)keyboardWillChangeFrame:(NSNotification *)note { // 键盘显示\隐藏完毕的frame CGRect frame = [note.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue]; // 修改底部约束 self.bottomSapce.constant = XMGScreenH - frame.origin.y; // 动画时间 CGFloat duration = [note.userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue]; // 动画 [UIView animateWithDuration:duration animations:^{ [self.view layoutIfNeeded]; }]; }

    [[NSNotificationCenter defaultCenter] removeObserver:self];

收藏
0
sina weixin mail 回到顶部