Skip to content

Instantly share code, notes, and snippets.

@lukeredpath
Created July 26, 2011 11:54
Show Gist options
  • Save lukeredpath/1106579 to your computer and use it in GitHub Desktop.
Save lukeredpath/1106579 to your computer and use it in GitHub Desktop.
Resizing tableview to accomodate keyboard
- (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