- (void)viewDidLoad {
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardHidden:) name: UIKeyboardWillHideNotification object:nil];
}
-(void)keyboardShow:(NSNotification *)noti{
CGRect keyBoardRect = [noti.userInfo[UIKeyboardFrameEndUserInfoKey]CGRectValue];
CGFloat deltaY = keyBoardRect.size.height;
//self.keyboardView是自己定义的一个视图,里面包含一个textview 输入框
[UIView animateWithDuration:[noti.userInfo[UIKeyboardAnimationDurationUserInfoKey]floatValue] animations:^{
self.keyboardView.transform = CGAffineTransformMakeTranslation(0, -deltaY);
}];
}
-(void)keyboardHidden:(NSNotification *)noti{
[UIView animateWithDuration:[noti.userInfo[UIKeyboardAnimationDurationUserInfoKey]floatValue] animations:^{
self.keyboardView.transform = CGAffineTransformIdentity;
}];
}