First, you have to listen to the keyboard events, the two most basic events:
Uikeyboardwillshownotification
Uikeyboardwillhidenotification
Uikeyboard...
Some new iOS 5
Uikeyboarddidchangeframenotification (will)
Generally, the first two events can be used to complete your tasks. Adding the nsnotification parameter to your event processing method gives you more information:
View plainprint?
-(Void) keyboardwillshow :( nsnotification *) Notification
{
Cgpoint begincentre = [[Notification userinfo] valueforkey: uikeyboardcenterbeginuserinfokey] cgpointvalue];
Cgpoint endcentre = [[Notification userinfo] valueforkey: uikeyboardcenterenduserinfokey] cgpointvalue];
Cgrect keyboardbounds = [[[Notification userinfo] valueforkey: uikeyboardboundsuserinfokey] cgrectvalue];
Cgrect keyboardframes = [[[Notification userinfo] valueforkey: uikeyboardframeenduserinfokey] cgrectvalue];
Uiviewanimationcurve animationcurve = [[Notification userinfo] valueforkey: uikeyboardanimationcurveuserinfokey] intvalue];
Nstimeinterval animationduration = [[Notification userinfo] valueforkey: uikeyboardanimationdurationuserinfokey] doublevalue];
}
If you wantProgramUsing the keyboard height and width, never try to manually specify, dynamic acquisition is also very simple and must be accurate, there will be no keyboard
Block the input box.
You can use these parameters to make the animation consistent with the keyboard. Suppose you want to place a widget on a window and want it to interact in the same way as the keyboard,
If you simply do a down offset animation, it cannot be done well, because when you want to pop it out from the navigation bar, the keyboard animation at this time is
You can use the frame obtained by uikeyboardframeenduserinfokey to offset the value on the X axis.
If you do not want to use the default keyboard for some special fields, but use a picker like Picker, you only need to set inputview, replace the keyboard with your custom view. If you want to add another view on the keyboard, such as toolbar, you do not need to control the position of the toolbar by yourself, you only need to set inputaccessoryview. The default value is nil. The set view is displayed above inputview when your control becomes the first responder.
On the uiscrollview (which inherits the uitableview), when you touch the control to make it the first responder, the system automatically adjusts the position to avoid the keyboard blocking control. IfCodeUsing becomefirstresponder to make it the first responder will not be automatically adjusted. You can set contentoffset to adjust manually. For other views, the simplest way is to modify the frame attribute of the control so that the control is always displayed in the visible area.