**键盘的通知
:**
//UIKeyboardWillShowNotification(键盘即将显示)
//UIKeyboardDidShowNotification(键盘已经显示)
//UIKeyboardWillHideNotification(键盘即将隐藏)
//UIKeyboardDidHideNotification(键盘已经隐藏)
//UIKeyboardWillChangeFrameNotification(键盘的位置尺寸即将发生 改变)
//UIKeyboardDidChangeFrameNotification(键盘的位置尺寸已经发生 改变)
1.订阅通知键盘的位置尺寸即将发生 改变
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillChangeFrame:) name:UIKeyboardWillChangeFrameNotification object:nil];
2.例 键盘弹出 弹回
- (void)keyboardWillChangeFrame:(NSNotification *)noti
{
CGFloat duration = [noti.userInfo[@"UIKeyboardAnimationDurationUserInfoKey"] floatValue];
CGRect frame = [noti.userInfo[@"UIKeyboardFrameEndUserInfoKey"] CGRectValue];
CGFloat offsetY = frame.origin.y - self.view.frame.size.height;
[UIView animateWithDuration:duration animations:^{
self.view.transform = CGAffineTransformMakeTranslation(0, offsetY);
}];
}
- 最后不要忘了退订通知
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}