Solution for keyboard input screen up-shift in IOS development _ios

Source: Internet
Author: User

In the iOS open method often encounter the keyboard shielding screen things (such as the input account password verification code, etc.), so that the original is not a large screen directly accounted for more than half of the position, this does not matter, the key is to block the button below. In this case, the button event can not be triggered, the best solution is when the information input to the entire screen to move a keyboard position, or move up to the specified location.

First general input words are used is uitextfield, so to monitor when users start input and when the end of input, directly set the agent on the line, to comply

Uitextfielddelegate agreement.

Follow the Protocol @interface Viewcontroller () <UITextFieldDelegate>//Setting Properties @property (Nonatomic,strong) uitextfield* UITF;
Set up Agent Uitf.delegate=self; Proxy method//keyboard pop-up screen up-(void) textfielddidbeginediting: (Uitextfield *) TextField {//If more than one input, such as registration and login, can be based on different input boxes to move up different positions,
Thus more humanized//keyboard height 216//Sliding effect (animation) Nstimeinterval animationduration = 0.30f;
[UIView beginanimations:@ "Resizeforkeyboard" context:nil];
[UIView setanimationduration:animationduration]; Move the y-coordinate of the view up to make room for the display of the soft keyboard self.view.frame = CGRectMake (0.0f, -100.0f/* screen up the height of the move, you can set yourself * * *, 
Self.view.frame.size.width, Self.view.frame.size.height);
[UIView commitanimations]; //Cancel the first response, that is, the input is complete, the screen is restored to the original-(void) textfielddidendediting: (Uitextfield *) TextField {//Sliding effect Nstimeinterval
Animationduration = 0.30f;
[UIView beginanimations:@ "Resizeforkeyboard" context:nil];
[UIView setanimationduration:animationduration]; 
Restore Screen self.view.frame = CGRectMake (0.0f, 0.0f, Self.view.frame.size.width, self.view.frame.size.height);
[UIView commitanimations]; }

Next, cancel the first response.

Usually add a click gesture on the current view, so you can cancel the first response of the keyboard, but there is a disadvantage, such as: Because the registration of the login page when the screen moved up,

will display the registration or login page, if you add a click gesture then will overwrite the button click event, that is, clearly saw the button, but the click did not respond, then how to do?

How to achieve the registration of the button events are logged in, click on the other places can also cancel the keyboard's first response.

It's actually very simple, and my solution is this.

Create a button that is as large as the screen, and all controls are placed on this button, and the Click event of the button is the first response to cancel the input box. That's it.

The above is a small set to introduce the development of iOS keyboard input screen on the solution, hope to help everyone, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

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.