1. First register system notification
monitor keyboard notifications [[Nsnotificationcenter Defaultcenter] addobserver:self selector: @selector ( Keyboardwillchangeframenotification:) name:uikeyboardwillchangeframenotification Object:nil];
2. The corresponding processing when the keyboard is about to change
-(void) Keyboardwillchangeframenotification: (nsnotification *) note{ // Time to remove the keyboard animation (according to userinfo key----Uikeyboardanimationdurationuserinfokey) CGFloat duration = [note.userinfo[uikeyboardanimationdurationuserinfokey] floatvalue]; //gets the last frame of the keyboard (according to userinfo key----uikeyboardframeenduserinfokey = "nsrect: {{0, 227}, {320, 253}";) cgrect keyboardframe = [note.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue]; //calculation controller view requires translation distance CGFloat transformY = keyboardframe.origin.y - self.view.frame.size.height; //Performing animations [UIView animateWithDuration:duration animations:^{ //Pan self.view.transform = cgaffinetransformmaketranslation (0, Transformy); }];}
3. It's not over yet (there is a hidden memory) and you need to rewrite the Dealloc method
-(void) dealloc{
// You must override the Dealloc method after using notification hubs to release (ARC) ( non- arc also needs to write [super Dealloc] ;)
Removeobserver and Addobserver correspond.
[[nsnotificationcenter defaultcenter] removeobserver: Self ];
}
Automatically adjusts the view location based on the pop-up hide of the keyboard