////VIEWCONTROLLER.M//text////Created by LDW on 16/1/22.//copyright©2016 year LDW. All rights reserved.//#import<UIKit/UIKit.h>#import "ViewController.h"@interfaceViewcontroller ()@end@implementationViewcontroller- (void) viewdidload {[Super viewdidload]; Uitextview*TEXTV =[[Uitextview alloc] initWithFrame:self.view.bounds]; [Self.view ADDSUBVIEW:TEXTV]; //1. Add Notifications [[Nsnotificationcenter defaultcenter] addobserver:self selector: @selector (keyboardchange:) Name: Uikeyboardwillshownotification Object:nil]; //keyboard will appear uikeyboardwillshownotification//keyboard has appeared uikeyboarddidshownotification//The keyboard will be hidden uikeyboardwillhidenotification//Keyboard has been hidden uikeyboarddidhidenotification }//2. The keyboard has been triggered by a call- (void) Keyboardchange: (Nsnotification *) noti{NSLog (@"%@", Noti);//Print Noti /*0x7f84584d1000 {name = uikeyboarddidshownotification; userInfo = {//Keyboard animation performs rhythm Uikeyboardanimationcurveuserinf Okey = 7; Keyboard animation Time Uikeyboardanimationdurationuserinfokey = "0.25"; Keyboard bounds Uikeyboardboundsuserinfokey = "Nsrect: {{0, 0}, {375, 258}}"; Keyboard Start Center Uikeyboardcenterbeginuserinfokey = "Nspoint: {187.5, 796}"; End of Keyboard Center Uikeyboardcenterenduserinfokey = "Nspoint: {187.5, 538}"; The position before the keyboard begins the animation (that is, when it disappears) Uikeyboardframebeginuserinfokey = "Nsrect: {{0, 667}, {375, 258}}"; The position after the keyboard finishes the animation (that is, it pops up) Uikeyboardframeenduserinfokey = "Nsrect: {{0, 409}, {375, 258}}"; Uikeyboardislocaluserinfokey = 1; }} */ //3. So how do you get this value? nsdictionary *nokey = [Noti userInfo]; Nsvalue *value = nokey[@ "Uikeyboardboundsuserinfokey"]; //Note that this value is of type CGRect (so the Cgrectvalue method must be called below ) NSLog (@ "%f" , [value cgrectvalue].size.height]; }@end
There are errors also forget you pointed out, if this article help you, or you have any suggestions and additions, can leave a message to tell me Oh!
[IOS] using notifications to implement a listening system keyboard