Keyboard occlusion control (textfield/textview...), textfieldtextview
The conventional notification method is used.
// Solve the problem of keyboard occlusion
// Select didShow because the keyboard height is required.
// WillHide is selected because the view frame reset takes precedence over the absence of the keyboard. Otherwise, the view frame is inconsistent.
[[Nsicationcenter center defaultCenter] addObserver: self selector: @ selector (handler :) name: jsonobject: nil]; [[nsicationicationcenter defaultCenter] addObserver: self selector: @ selector (keyboardWasHide :) name: UIKeyboardWillHideNotification object: nil];
Trigger Method
-(Void) keyboardWasShown :( NSNotification *) notification {// obtain the keyboard height NSValue * value = notification. userInfo [UIKeyboardFrameBeginUserInfoKey]; CGFloat keyBoradHeight = [value CGRectValue]. size. height; NSNumber * animationTime = notification. userInfo [UIKeyboardAnimationDurationUserInfoKey]; double time = [animationTime doubleValue]; // obtain the float a = self distance from the blocked control to the bottom of the controller. view4.frame. origin. y + self. view4.frame. size. height; float B = self. view. frame. size. height-a; if (B <keyBoradHeight) {// animation effect [UIView animateWithDuration: time animations: ^ {// the keyboard is blocked by CGRect viewCGrect = self. view. frame; // The view should be moved up so it is-viewCGrect. origin. y = viewCGrect. origin. y-(keyBoradHeight-B); [self. view setFrame: viewCGrect];} completion: nil];}-(void) keyboardWasHide :( NSNotification *) notification {NSValue * value = notification. userInfo [UIKeyboardFrameBeginUserInfoKey]; CGFloat keyBoradHeight = [value CGRectValue]. size. height; float a = self. view4.frame. origin. y + self. view4.frame. size. height; float B = self. view. frame. size. height-a; CGRect viewCGrect = self. view. frame; viewCGrect. origin. y = viewCGrect. origin. y + (keyBoradHeight-B); [self. view setFrame: viewCGrect];}
Last remove notification
-(void)viewWillDisappear:(BOOL)animated{ [super viewWillDisappear:animated]; [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil]; [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardDidShowNotification object:nil];}