-(void) viewdidload {nsnotificationcenter*center =[Nsnotificationcenter Defaultcenter]; //registering a keyboard display notification[Center addobserver:self selector: @selector (keyboardwillshow:) name:uikeyboardwillshownotificationObject: nil]; //Register for keyboard Hide notifications[Center addobserver:self selector: @selector (keyboardwillhide:) name:uikeyboardwillhidenotificationObject: nil];}-(void) Viewdiddisappear: (BOOL) animated{//Remove Notifications[[Nsnotificationcenter Defaultcenter] removeobserver:self name:uikeyboardwillshownotificationObject: nil]; [[Nsnotificationcenter Defaultcenter] removeobserver:self name:uikeyboardwillhidenotificationObject: nil];}- (void) Keyboardwillshow: (Nsnotification *) notification{nsdictionary*info; Cgsize kbsize; DoubleKbheight; CGFloat oversize; Doubleduraction; Info=Notification.userinfo; Kbsize=[Info objectforkey:uikeyboardframeenduserinfokey]cgrectvalue].size; Kbheight=Kbsize.height; Oversize= (self.view.frame.size.height-kbheight)-(TEXTFIELD.FRAME.ORIGIN.Y + textfield.frame.size.height+5); Duraction=[info Objectforkey:uikeyboardanimationdurationuserinfokey] Doublevalue]; if(Oversize <0) {[UIView animatewithduration:duraction animations:^{self.view.frame= CGRectMake (0.0f, oversize, self.view.frame.size.width, self.view.frame.size.height); }]; }}-(void) Keyboardwillhide: (Nsnotification *) notification{DoubleDuraction =[[Notification.userinfo Objectforkey:uikeyboardanimationdurationuserinfokey] doublevalue]; [UIView animatewithduration:duraction animations:^{self.view.frame= CGRectMake (0,0, Self.view.frame.size.width, self.view.frame.size.height); }];}
ios-using keyboard notifications to handle the problem of occlusion control when keyboard appears