IOS Get Keyboard height

Source: Internet
Author: User

-(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];

}

-(void) Keyboardwillshow: (nsnotification *) anotification

{

Get the height of the keyboard

/*

iphone 6:

Chinese

2014-12-31 11:16:23.643 demo[686:41289] keyboard height is 258

2014-12-31 11:16:23.644 demo[686:41289] keyboard width is 375

English

2014-12-31 11:55:21.417 demo[1102:58972] keyboard height is 216

2014-12-31 11:55:21.417 demo[1102:58972] keyboard width is 375

iphone 6 Plus:

English:

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

Chinese:

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:

2014-12-31 11:19:36.452 demo[755:43233] keyboard height is 216

2014-12-31 11:19:36.452 demo[755:43233] keyboard width is 320

ipad Air:

2014-12-31 11:28:32.178 demo[851:48085] keyboard height is 264

2014-12-31 11:28:32.178 demo[851:48085] keyboard width is 768

ipad2:

2014-12-31 11:33:57.258 demo[1014:53043] keyboard height is 264

2014-12-31 11:33:57.258 demo[1014:53043] keyboard width is 768

*/

Nsdictionary *userinfo = [Anotification userInfo];

Nsvalue *avalue = [UserInfo Objectforkey:uikeyboardframeenduserinfokey];

CGRect keyboardrect = [Avalue cgrectvalue];

int height = keyboardRect.size.height;

int width = keyboardRect.size.width;

NSLog (@ "Keyboard height is%d", height);

NSLog (@ "Keyboard width is%d", width);

}

Called when the key exits

-(void) Keyboardwillhide: (nsnotification *) anotification

{

}

IOS Get 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.