Get iOS device keyboard height

Source: Internet
Author: User

Recently made a custom keyboard, first of all to know the iOS device a variety of keyboard height, below to say how to get the height of the keyboard.

The main is to use the keyboard pop-up notification.

1, first of all to build a project.

2, in the project-(void) viewdidload; add keyboard pop-up and hidden notifications in the function, with the following code:

1         //increase monitoring to receive messages when the keyboard appears or changes2 [[Nsnotificationcenter Defaultcenter] addobserver:self3 selector: @selector (keyboardwillshow:)4 name:uikeyboardwillshownotification5                                             Object: nil];6 7         //increased monitoring, when the key exits when the message is received8 [[Nsnotificationcenter Defaultcenter] addobserver:self9 selector: @selector (keyboardwillhide:)Ten name:uikeyboardwillhidenotification One                                             Object: nil];

3, when the notification is written 2 functions, in response to notification-(void) keyboardwillshow; -(void) keyboardwillhide;

In these 2 functions you can get some properties of the keyboard, the code is as follows:

1- (void) Keyboardwillshow: (Nsnotification *) Anotification2 {3     //get the height of the keyboard4     /*5 iphone 6:6 English7 2014-12-31 11:16:23.643 demo[686:41289] keyboard height is 2588 2014-12-31 11:16:23.644 demo[686:41289] keyboard width is 3759 EnglishTen 2014-12-31 11:55:21.417 demo[1102:58972] keyboard height is 216 One 2014-12-31 11:55:21.417 demo[1102:58972] keyboard width is 375 A       - iphone 6 Plus: - English: the 2014-12-31 11:31:14.669 demo[928:50593] keyboard height is 226 - 2014-12-31 11:31:14.669 demo[928:50593] keyboard width is 414 - English: - 2015-01-07 09:22:49.438 demo[622:14908] keyboard height is 271 + 2015-01-07 09:22:49.439 demo[622:14908] keyboard width is 414 -       + iphone 5: A 2014-12-31 11:19:36.452 demo[755:43233] keyboard height is 216 at 2014-12-31 11:19:36.452 demo[755:43233] keyboard width is -       - ipad Air: - 2014-12-31 11:28:32.178 demo[851:48085] keyboard height is - 2014-12-31 11:28:32.178 demo[851:48085] keyboard width is 768 -       in ipad2: - 2014-12-31 11:33:57.258 demo[1014:53043] keyboard height is to 2014-12-31 11:33:57.258 demo[1014:53043] keyboard width is 768 +      */ -Nsdictionary *userinfo =[Anotification UserInfo]; theNsvalue *avalue =[UserInfo Objectforkey:uikeyboardframeenduserinfokey]; *CGRect Keyboardrect =[Avalue Cgrectvalue]; $     intHeight =KeyboardRect.size.height;Panax Notoginseng     intwidth =KeyboardRect.size.width; -NSLog (@"keyboard height is%d", height); theNSLog (@"keyboard width is%d", width); + } A  the //called when the key exits +- (void) Keyboardwillhide: (Nsnotification *) Anotification - { $}

Get iOS device keyboard height

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.