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