Use KeyBoardUtil to process the soft keyboard pop-up

Source: Internet
Author: User

 

The iPhone's keyboard is 216 pixels high. programmers have to adjust the window view when the keyboard is popped up to avoid the input control being blocked by the keyboard.

 

IPhone programmers generally use observer objects that register Soft Keyboard Events to deal with this problem. When the keyboard pops up, the View of the form is moved up. When the keyboard is hidden, the View of the form is restored to its original position, thus avoiding the occlusion of the input control.

 

KeyBoardUtil is a Class I wrote. It uses the above principles, but it is encapsulated to facilitate the use of programmers.

 

It is easy to use. First, import the header file in the ViewController to be used:

 

# Import "KeyBoardUtil. h"

 

Declare a KeyBoardUtil member variable in the class:

 

KeyBoardUtil * keyboardUtil;

 

In the class initialization method, initialize the KeyBoardUtil object:

 

KeyboardUtil = [[KeyBoardUtil alloc] initWithOwner: self offline sety: 100];

 

The ower parameter is self, and the offsetY parameter specifies the pixels in the window View to be moved up when the keyboard pops up. Generally, the maximum value is 216 in the soft keyboard height, but it can also be removed, determine how much to move according to the actual situation.

 

Then, call the reg and unreg methods of KeyBoardUtil in the display and hide events of the View Controller:

 

# Pragma mark registration/logout keyboard pop-up notification method www.2cto.com

 

-(Void) viewWillDisappear :( BOOL) animated

 

{

 

[KeyboardUtil unreg];

 

[KeyboardUtil release];

 

}

 

 

 

-(Void) viewWillAppear :( BOOL) animated

 

{

 

[KeyboardUtil reg];

 

 

 

}

 

Is it much more convenient for all the code? If you like this little thing, you can go to the resource to download: http://download.csdn.net/detail/kmyhy/3887363

 

From kmyhy's column

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.