When TextFiled or TextView is used, the editing area is often blocked because the keyboard pops up, and the Chinese Keyboard calls the keyboardWillShow listener twice because of pinyin, now I have posted a method that I understand myself.
-(Id) initWithNibName :( NSString *) nibNameOrNil bundle :( NSBundle *) attributes {self = [super initWithNibName: nibNameOrNil bundle: nibBundleOrNil]; if (self) {// Custom initialization // Add the listener to [[nsnotifcenter center defacenter center] addObserver: self selector: @ selector (keyboardWillShow :) name: jsonobject: nil]; [[nsicationicationcenter defacenter center] addObserver: self selector: @ selector (keyboardWillHide :) name: UIKeyboardWillHideNotification object: nil];} return self ;}
@ Property (nonatomic, assign) CGRect tableViewRect; // set a rect to save the rect of the view you want to raise
- (void)keyboardWillShow:(NSNotification *)notif { self.keyBoardRect = [[notif.userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue]; [UIView animateWithDuration:0.5 animations:^{ CGRect tbRect = self.tableViewRect; tbRect.origin.y -=self.keyBoardRect.size.height; self.tableView.frame = tbRect; } completion:^(BOOL finish){ }]; }- (void)keyboardWillHide:(NSNotification *)notif { [UIView animateWithDuration:0.5 animations:^{ self.tableView.frame = self.tableViewRect; } completion:^(BOOL finish){ }]; }
Using a temporary variable for a transit saves a lot of complicated logic, so that even if the Chinese language is played twice, it will not be affected.