1.
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
} - (void)registerNotification {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showKeyboard:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(hideKeyboard:) name:UIKeyboardWillHideNotification object:nil];
} #pragma mark - keyboard
- (void)showKeyboard:(NSNotification *)noti {
NSDictionary *info=[noti userInfo]; NSTimeInterval duration = [info[UIKeyboardAnimationDurationUserInfoKey] doubleValue];
UIViewAnimationOptions options = [info[UIKeyboardAnimationCurveUserInfoKey] unsignedIntegerValue] << ; CGRect keyboardRect = [info[UIKeyboardFrameEndUserInfoKey] CGRectValue];
CGFloat keyboardHeight = MIN(CGRectGetWidth(keyboardRect), CGRectGetHeight(keyboardRect)); [UIView animateWithDuration:duration delay: options:options animations:^{
CGFloat compareH = self.tableView.contentSize.height -(self.view.height - - - keyboardHeight);
if (compareH > ) {
if (compareH < keyboardHeight) {
self.tableView.transform = CGAffineTransformMakeTranslation(, -compareH);
} else {
self.tableView.transform = CGAffineTransformMakeTranslation(, -keyboardHeight);
}
} self.bottomView.transform = CGAffineTransformMakeTranslation(, -keyboardHeight); } completion:nil];
} - (void)hideKeyboard:(NSNotification *)noti { NSDictionary *info=[noti userInfo]; NSTimeInterval duration = [info[UIKeyboardAnimationDurationUserInfoKey] doubleValue];
UIViewAnimationOptions options = [info[UIKeyboardAnimationCurveUserInfoKey] unsignedIntegerValue] << ; [UIView animateWithDuration:duration delay: options:options animations:^{ self.tableView.transform = CGAffineTransformIdentity;
self.bottomView.transform = CGAffineTransformIdentity; } completion:nil]; }