新增監聽者
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardwasChange:) name:UIKeyboardWillChangeFrameNotification object:nil];
複製程式碼
監聽鍵盤之後的操作 可以根據自己的需要調整高度的大小
- (void)keyboardwasChange:(NSNotification *)info {
CGRect keyFrame = [info.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
CGFloat tY = keyFrame.origin.y - self.view.frame.size.height - 64;
self.view.transform = CGAffineTransformMakeTranslation(0, tY);
}
複製程式碼