-
- Registering keyboard notifications
#pragma mark - 键盘通知- (void)addNoticeForKeyboard { //注册键盘出现的通知 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil]; //注册键盘消失的通知 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];}
Keyboard Display event-(void) Keyboardwillshow: (nsnotification *) Notification {//Get keyboard height, on different devices, and in Chinese and English are different cgfloat kbheight = [[ Notification.userinfo Objectforkey:uikeyboardframeenduserinfokey] cgrectvalue].size.height; Calculates the distance from the top of the keyboard to the bottom of the Inputtextview panel (plus the custom buffer distance interval_keyboard) cgfloat offset = (textview.frame.origin.y+ Textview.frame.size.height+interval_keyboard)-(self.view.frame.size.height-kbheight); Gets the animation time of the keyboard so that it can be more coherent when the view is moved double duration = [[Notification.userinfo objectforkey: Uikeyboardanimationdurationuserinfokey] Doublevalue]; Move the view up to the calculated offset if (Offset > 0) {[UIView animatewithduration:duration animations:^{Self.view.frame = CGRectMake (0.0f,-offset, Self.view.frame.size.width, self.view.frame.size.height); }]; }}///Keyboard Vanishing Event-(void) Keyboardwillhide: (Nsnotification *) Notify {//Keyboard animation time double duration = [[Notify.userinfo object] Forkey:uikeyboardanimationdurationuserinfokey] Doublevalue]; The view sinks back to the original [UIView animateWithduration:duration animations:^{self.view.frame = CGRectMake (0, 0, Self.view.frame.size.width, Self.view.frame. Size.Height); }];}
The struggling snail
Links: http://www.jianshu.com/p/4e235e952b0c
Source: Pinterest
ios-The entire view moves when the input box is obscured by the keyboard