// 监听键盘的位置改变
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
// 监听键盘的通知
[center addObserver:self selector:@selector(keyboardWillChangeFrame:) name:UIKeyboardWillChangeFrameNotification object:nil];
// 收到键盘的frame将要改变的通知时会调用此方法
- (void)keyboardWillChangeFrame:(NSNotification *)note {
// 拿到键盘弹出或隐藏后的frame
CGRect keyboardFrame = [note.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
// 键盘弹出时
// 667 - 667 = 0
// 控制器要移动的位置 = 键盘显示后或隐藏后的y - 控制器的高
CGFloat transformY = keyboardFrame.origin.y - self.view.bounds.size.height;
// 让控制器跟随键盘的弹出和隐藏来移动
self.view.transform = CGAffineTransformMakeTranslation(0, transformY);
}
//这个是回到原来的位置
self.view.transform = CGAffineTransformIdentity;