IOS solves the problem of keyboard blocking input boxes

Source: Internet
Author: User

A problem is found in iOS development. Sometimes when the input box is low, when the input is edited, the pop-up keyboard will block the input box, so that users cannot see the real-time input, make interface interaction extremely unfriendly.

After checking the information, the problem was finally solved.

Solution:

1. input box listeningUicontroleventeditingdidbegin event,When the user starts to input, the entire view is moved up.

2. input box listeningUicontroleventeditingdidend event,When the user finishes the input, the entire view is moved down and restored to the original position.

Input box listening event:

 
[Textfield addtarget: Self action: @ selector (textfielddidbeginediting :) forcontrolevents: Inputs]; [textfield addtarget: Self action: @ selector (textfielddidendediting :) forcontrolevents: Inputs];

RESPONSE event:

-(Void) textfielddidbeginediting :( uitextfield *) textfield {// when you start editing, move the entire if (textfield. tag = 0) {[self moveview:-20];} If (textfield. tag = 1) {[self moveview:-60] ;}}-(void) textfielddidendediting :( uitextfield *) textfield {// when editing ends, the overall move down if (textfield. tag = 0) {[self moveview: 20];} If (textfield. tag = 1) {[self moveview: 60] ;}}-(void) moveview :( float) move {nstimeinterval animationduration = 0.30f; cgrect frame = self. view. frame; frame. origin. X + = move; // the X axis of the view moves up self. view. frame = frame; [uiview beginanimations: @ "resizeview" context: Nil]; [uiview setanimationduration: animationduration]; self. view. frame = frame; [uiview commitanimations]; // set and adjust the animation effect on the Interface}

When there are several input boxes, the tag attribute of the input box is used to determine which input box the user has clicked, provided that you must assign a value to the tag first. This method is particularly effective for the embedded dialog boxes in tableview.

Another way is to know the names of input boxes and use the names to determine which input boxes the user has clicked.

Only when the user clicks the input box can the distance to be moved in the input box be determined.

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.