IOS keyboard input screen move up, ios keyboard input move up
In IOS activation, the screen is often blocked by the keyboard (such as entering the account and password verification code), so that the screen that was originally not large occupies half or more places, this doesn't matter. The key is to block the following buttons. In this case, the button event cannot be triggered. The best solution is to move the entire Screen to a keyboard location or to a specified location when you input the information.
Generally, UITextField is used for input. Therefore, you can set the proxy directly to listen to the user's start input and end input.
UITextFieldDelegate protocol.
// Follow the agreement
@ Interface ViewController () <UITextFieldDelegate>
// Set attributes
@ Property (nonatomic, strong) UITextField * UITF;
// Set proxy
UITF. delegate = self;
// Proxy method
// Move the screen up when the keyboard pops up
-(Void) textFieldDidBeginEditing :( UITextField *) textField
{
// If multiple inputs, such as registration and logon, you can move up different locations based on different input boxes to make them more user-friendly.
// 216 keyboard height
// 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,-100366f/* the height of the screen move up. You can set it by yourself */, self. view. frame. size. width, self. view. frame. size. height );
[UIView commitAnimations];
}
// Cancel the first response, that is, after the input is complete, the screen is restored to its original state.
-(Void) textFieldDidEndEditing :( UITextField *) textField
{
// Sliding effect
NSTimeInterval animationDuration = 0.30f;
[UIView beginAnimations: @ "ResizeForKeyboard" context: nil];
[UIView setAnimationDuration: animationDuration];
// Restore the screen
Self. view. frame = CGRectMake (0.0f, 0.0f, self. view. frame. size. width, self. view. frame. size. height );
[UIView commitAnimations];
}
Next let's talk about canceling the first response.
Generally, you can add a click gesture to the current View. In this way, you can cancel the first response of the keyboard. However, there is a drawback, such: because when the screen is moved up,
The registration or login page is displayed. if you add a click gesture, the Click Event of the button will be overwritten, that is, the button is clearly displayed, but the click does not respond, so what should we do?
How to achieve the event registration and login button are all in, click other places can also cancel the first response of the keyboard.
In fact, it is very simple. My solution is as follows:
Create a button, which is as big as the screen, and all the controls are placed on this button. The click event of this button is to cancel the first response in the input box. In this way, you can.