博客> 监听键盘
监听键盘
2017-05-26 11:57 评论:1 阅读:474 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 回到顶部