M Niu C original blog-enter the UI text box and press the keyboard to exit automatically and click the blank space to exit. Switch to the next text box, ui

Source: Internet
Author: User

M Niu C original blog-enter the UI text box and press the keyboard to exit automatically and click the blank space to exit. Switch to the next text box, ui

How do I disable the system pop-up keyboard?

1) processing of the system after the touch screen action occurs

Step 1: Find hitView

After the touch screen is captured, the system records the contact coordinates, sends the hitTest message to the window, and notifies the vertex coordinates. The window sends the hitTest message to all the direct sub-objects to notify the coordinate of the vertex, check whether the coordinates of the sub-object are in the list. If the coordinates are not in the list, nil is returned. If the coordinates are in the list, send messages to all direct sub-views until a sub-view no longer exists, and the contacts are in it, this object is returned, and the system finds the object of this click.


Step 2: Find the hitView and execute the event response.

Check whether the hitView provided the event response. If yes, the system executes the response. If no response is provided, the event is passed to the parent view to check whether the parent view responds, if there is no response, continue to pass up until appdelegate does not respond, then discard this event. This process uploads the event layer by layer and searches for the response in sequence, which is called the response chain.


2) pop-up keyboard

When the contact is a text box, the system automatically sets the text box as the first responder.

Became the first responder becomeFirstResponder

-(IBAction) openKeyboard :( id) sender {

// Set the text box to the first responder

// The keyboard is automatically displayed.

[Self. textFieldbecomeFirstResponder];

}


3) Close the keyboard

Discard the first responder identity resignFirstResponder



3. Disable the keyboard in two ways

1) First: Give up the identity of the first responder

[TextField resignFirstResponder]


2) second: end the editing status of the parent view of the text box.

[View endEditing]

-(IBAction) closeKeyboard :( id) sender {

// Method 1: Set the text box to discard the first responder identity

// [Self. textField resignFirstResponder];

// Method 2: end the editing mode of the parent View

[Self. viewendEditing: YES];

}


4. When to disable the keyboard

1) First: Click the return button in the lower right corner of the keyboard.

Connect textField, and select the Did End On Exit event.

2) Method 2: click a blank area

Override touchesBegan method of vc

// Time 1: Click the return button in the lower right corner.


-(IBAction) closeKeyboard2 :( id) sender {

// Close the keyboard

// [Self. textField resignFirstResponder];

[Self. viewendEditing: YES];

}


// Time 2: Click the blank area

// Rewrite the touchesBegan method of vc.

-(Void) touchesBegan :( NSSet *) touches withEvent :( UIEvent *) event {

[Self. viewendEditing: YES];

}



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.