On the chat page, use the IQKeyboardManager navigation bar and the solution for moving up the entire page.

Source: Internet
Author: User

On the chat page, use the IQKeyboardManager navigation bar and the solution for moving up the entire page.
Problem:

When the third-party library IQKeyboardManager is used, the entire page is moved up, and the navigation bar page is removed from the display range. The preceding message is invisible on the chat interface.

Solution:

Note: Using IQKeyboardManager in the chat interface as a third-party library cannot solve this problem. At least I have not found a solution. Create a UI using ib on the internet, change the view of the Controller to scrollview, or create the UI with pure code, override the loadView method, and then set self. view = scrollview. No trial. It is too troublesome.
Solution: on the chat page, disable IQKeyBoard and monitor the keyboard to bring up notifications. Write the input box and move it up and down with the keyboard. I can see a good solution on the Internet: When the keyboard pops up, set the height of the message list tableView to (screen height-input box height-keyboard height), and move the input box up; when the keyboard disappears, the height of tableView is set to (screen height-the height of the input box), and the input box is moved down. This perfectly solves the problem of Message Display and keyboard occlusion in the chat list.

Keyboard monitoring code:
-(Void) viewDidLoad {self. listener = NO; // notification for listening to the keyboard [[NSNotificationCenter defacenter center] addObserver: self selector: @ selector (keyboardwillchangeframenoworkflow :) name: jsonobject: nil];}-(void) viewDidAppear :( BOOL) animated {[super viewDidAppear: animated]; _ updated = [[IQKeyboardManager sharedManager] isEnabled]; [[IQKeyboardManager sharedManager] setEnable: NO];}-(void) viewDidDisappear :( BOOL) animated {[super viewWillDisappear: animated]; [[IQKeyboardManager sharedManager] setEnable: _ wasKeyboardManagerEnabled];} /*** click the return button (the button at the bottom right corner of the keyboard) to call */-(BOOL) textFieldShouldReturn :( UITextField *) textField {[self sendMessage]; return YES ;} /*** call the */-(void) keyboardWillChangeFrameNotify :( NSNotification *) keyboardwillchangeframenoy {// 0 when the frame (position and size) is changed on the keyboard. the keyboard animation time CGFloat duration = [127y. userInfo [UIKeyboardAnimationDurationUserInfoKey] doubleValue]; // 1. get the final frame CGRect keyboardFrame = [policy. userInfo [UIKeyboardFrameEndUserInfoKey] CGRectValue]; // 2. the distance between the view of the computing controller and CGFloat transformY = keyboardFrame. origin. y-self. view. frame. size. height; // 3. run the animation [UIView animateWithDuration: duration animations: ^ {self. myTableView. frame = CGRectMake (0, 0, SCREENW, SCREENH + transformY-self. inputView. height); self. tableViewBottomConstraint. constant =-transformY + 44; // The distance between the bottom of tableView and the bottom of the parent view is self. inputView. transform = CGAffineTransformMakeTranslation (0, transformY); [self scrollTableViewToBottom];}] ;}/ *** tableView quickly scrolls to the bottom */-(void) scrollTableViewToBottom {if (self. messageFrames. count) {NSIndexPath * indexPath = [NSIndexPath indexPathForRow :( self. messageFrames. count-1) inSection: 0]; [self. myTableView scrollToRowAtIndexPath: indexPath atScrollPosition: UITableViewScrollPositionBottom animated: YES] ;}- (void) dealloc {[[nsicationicationcenter defacenter center] removeObserver: self];}

Related Article

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.