键盘事件
1 - (void)buildNotification { 2 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShowWithNotification:) name:UIKeyboardWillShowNotification object:nil]; 3 4 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHideWithNotification:) name:UIKeyboardWillHideNotification object:nil]; 5 } 6 7 - (void)keyboardWillShowWithNotification:(NSNotification *)notification { 8 CGRect rect = [notification.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue]; 9 CGFloat height = rect.size.height - (kDevice_iPhoneX ? kFloatBottomDangerHeight : 0); 10 11 [UIView animateWithDuration:[notification.userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue] animations:^{ 12 _inputTextView.transform = CGAffineTransformMakeTranslation(0, - height); 13 }]; 14 } 15 16 - (void)keyboardWillHideWithNotification:(NSNotification *)notification { 17 [UIView animateWithDuration:[notification.userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue] animations:^{ 18 _inputTextView.transform = CGAffineTransformIdentity; 19 }]; 20 }