监听键盘
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardChangeFrame:) name:UIKeyboardWillChangeFrameNotification object:nil]; #pragma mark 监听方法 - (void)keyboardChangeFrame :(NSNotification *)note { CGFloat time = [note.userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue]; CGRect rect = [note.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue]; CGFloat endY = rect.origin.y; [UIView animateWithDuration:time animations:^{ self.view.transform = CGAffineTransformMakeTranslation(0, endY - [UIScreen mainScreen].bounds.size.height); }]; }
如有疑问,共同探讨,共同进步。