- (void)viewDidLoad {
[[IQKeyboardManager sharedManager] disableToolbarInViewControllerClass:[self class]];
[[IQKeyboardManager sharedManager] disableDistanceHandlingInViewControllerClass:[self class]];
}
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyBoardWillShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyBoardWillHide:) name:UIKeyboardWillHideNotification object:nil];
}
#pragma mark - 键盘处理
// 键盘即将显示
- (void)keyBoardWillShow:(NSNotification * )note{
CGRect rect= [note.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
CGFloat ty=rect.size.height;
[UIView animateWithDuration:[note.userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue] animations:^{
self.view.transform = CGAffineTransformMakeTranslation(0, -ty);
self.noticeLabel.transform = CGAffineTransformMakeTranslation(0, ty);
[self.eleTableView setContentInset:UIEdgeInsetsMake(ty, 0, 0, 0)];
}];
}
// 键盘即将退出
- (void)keyBoardWillHide:(NSNotification * )note{
__weak typeof(self) weakSelf = self;
[UIView animateWithDuration:[note.userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue] animations:^{
__strong typeof(self) strongSelf = weakSelf;
strongSelf.view.transform = CGAffineTransformIdentity;
strongSelf.noticeLabel.transform = CGAffineTransformIdentity;
[strongSelf.eleTableView setContentInset:UIEdgeInsetsMake(0, 0, 0,0)];
}];
}
//处理第一响应者
[[IQKeyboardManager sharedManager] resignFirstResponder];
网友评论