Created
July 26, 2011 11:54
-
-
Save lukeredpath/1106579 to your computer and use it in GitHub Desktop.
Resizing tableview to accomodate keyboard
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)resizeTableViewWithHeightOffset:(CGFloat)offsetHeight | |
animationDuration:(double)animationDuration | |
completion:(void (^)(BOOL))completionHandler | |
{ | |
[UIView animateWithDuration:animationDuration animations:^{ | |
CGRect frame = self.tableView.frame; | |
frame.size.height += offsetHeight; | |
self.tableView.frame = frame; | |
} completion:completionHandler]; | |
} | |
- (void)keyboardWillShow:(NSNotification *)note | |
{ | |
CGRect keyboardFrame = [[note.userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue]; | |
double animationDuration = [[note.userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue]; | |
CGFloat offsetHeight = keyboardFrame.size.height - self.tabBarController.tabBar.frame.size.height; | |
[self resizeTableViewWithHeightOffset:-offsetHeight animationDuration:animationDuration completion:^(BOOL complete) { | |
[self.tableView scrollFirstResponderIntoView]; | |
[self setKeyboardShowing:YES]; | |
}]; | |
} | |
- (void)keyboardWillHide:(NSNotification *)note | |
{ | |
CGRect keyboardFrame = [[note.userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue]; | |
double animationDuration = [[note.userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue]; | |
CGFloat offsetHeight = keyboardFrame.size.height - self.tabBarController.tabBar.frame.size.height; | |
[self resizeTableViewWithHeightOffset:offsetHeight animationDuration:animationDuration completion:^(BOOL complete) { | |
[self setKeyboardShowing:NO]; | |
}]; | |
}R |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment