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