When the keyboard pops up, the screen is adapted to the keyboard height.

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.