//接收键盘弹出的通知
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(presentKeyBoard:) name:UIKeyboardWillShowNotification object:nil];
//接收通知以后实现的代理方法
- (void)presentKeyBoard:(NSNotification *)notif {
//取得键盘的高度
NSValue *value = [notif.userInfo objectForKey:UIKeyboardBoundsUserInfoKey];
//NSValue->CGRect
CGRect rect = [value CGRectValue];
CGFloat height = CGRectGetHeight(rect);
[UIView animateWithDuration:0.25 animations:^{
_view.transform = CGAffineTransformMakeTranslation(0, -height);
_tabView.transform = CGAffineTransformMakeTranslation(0, -height);
}];
}
//键盘归位
[UIView animateWithDuration:.25 animations:^{
_view.transform = CGAffineTransformIdentity;
_tabView.transform = CGAffineTransformIdentity;
}];
输入框弹出键盘时自动上移
最新推荐文章于 2022-11-16 16:57:13 发布