iOS gets the height of the keyboard (simple and effective)

Source: Internet
Author: User

iOS gets the height of the keyboard(2013-03-06 17:45:31)
Tags:keyboardtextfieldtextviewios keyboard height Category: iOS notes
  1. -(void) Viewdidload

    {

    [Super Viewdidload];

    //Increase monitoring to receive messages when the keyboard appears or changes

    [[nsnotificationcenter defaultcenter] addobserver: Self

    selector:@selector (keyboardwillshow:)

    Name:uikeyboardwillshownotification

    object:nil];

    //increased monitoring, when the key exits when the message is received

    [[nsnotificationcenter defaultcenter] addobserver: Self

    selector:@selector (keyboardwillhide:)

    Name:uikeyboardwillhidenotification

    object:nil];

    }

    Called when the keyboard appears or changes

    -(void) Keyboardwillshow: (nsnotification *) anotification

    {

    //Get the height of the keyboard

    nsdictionary *userinfo = [anotification userInfo];

    Nsvalue *avalue = [UserInfo objectforkey: Uikeyboardframeenduserinfokey];

    cgrect keyboardrect = [Avalue cgrectvalue];

    int height = keyboardrect. size. height;

    }

    Called when the key exits

    -(void) Keyboardwillhide: (nsnotification *) anotification

    {

    }

iOS gets the height of the keyboard (simple and effective)

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.