Processing of iOS keyboard overlay input Box

Source: Internet
Author: User
Tags instance method

On a multiple input interface, there will be more than one Uitextfield type of input box. In order to scroll, we will add them to the UITableView cell to form a data entry interface that can slide up and down.

But character input is done by the system automatically pops up the soft keyboard, so when you select the cell at the bottom of the screen, it is covered by the soft keyboard area.

Similarly, because the input box is in the UITableView cell, you can scroll the cell in place on top of the soft pad-covered area. So that we can see the input box.

Now, we're going to implement this process.

We can simply scroll the cell to the top of the visible area of the table view.

UITableView provides this method of "scrollToRowAtIndexPath:atScrollPosition:animated:". As a first responders ' input box, it can be delegated by its method-(void) textfielddidbeginediting: (uitextfield*) TextField

Assign the value to a variable Lastedittextfield. The appearance and disappearance of the soft keyboard are registered in the View controller class and the method of implementing it. In this way, when the Uitextfield activates the eject keyboard, the system automatically submits a soft keyboard pop-up notification. A keyboard pop-up notification invokes a method.

The logic of this method is to get the cell that operates according to the location where Lastedittextfield is located, and then to scroll the cell to the top of the view visible area.

Cgpoint PT =lastedittextfield.center;

PT = [Self.tableview ConvertPoint:ptfromView:lastEditTextField.superview];

nsindexpath* Indexpath = [SELF.TABLEVIEWINDEXPATHFORROWATPOINT:PT];

[Self.tableview ScrollToRowAtIndexPath:indexPathatScrollPosition:UITableViewRowAnimationTop Animated:yes];

The most important thing in this code is to use the UIView instance Method-(Cgpoint) Convertpoint: (cgpoint) point Fromview according to the value of Lastedittextfield.center: (UIView *) View converts it to a value under the Self.tableview coordinate system. According to the value of lastedittextfield.center in the new coordinate system, the UITableView instance method is used to scrollToRowAtIndexPath:atScrollPosition:animated: Scroll the cell to the top of the screen.

When the keyboard disappears, the system sends another notification and restores the screen to its original location.

Scroll the input box to the top, although it meets our input visibility requirements. However, if you can only scroll to the top of the soft keyboard, rather than the top of the UITableView, you do not need to scroll when the input box is not in the area covered by the keyboard. Such a deal would be a more satisfying result.

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.