首先
//注冊通知:鍵盤frame位置和尺寸發(fā)生改變的通知
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillChangeFrame:) name:UIKeyboardWillChangeFrameNotification? object:nil];
然后?
// 獲得屏幕的高度
CGFloat screenH = [UIScreen mainScreen].bounds.size.height;
// 獲得通知信息
NSDictionary *userInfo = note.userInfo;
// 獲得鍵盤顯示完畢或隱藏完畢的frame
CGRect keyboardFrame =? [userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
// 獲得鍵盤的y值
CGFloat keyboardY = keyboardFrame.origin.y;
// 計(jì)算平移的距離
CGFloat translationY = keyboardY - screenH? ;
// 平移控制器的view
// 顯示平移的距離是:-258 隱藏是 0
self.view.transform = CGAffineTransformMakeTranslation(0, translationY);