Skills required for iOS keyboard-based programming

Source: Internet
Author: User

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.

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.