Created
February 16, 2015 07:37
-
-
Save james-b-kelly/4bfc06eb6a52e1f48815 to your computer and use it in GitHub Desktop.
Adjust table/collection view height for keyboard.
This file contains 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
//Set up your tableview/collection view in IB with a bottom layout constraint with an IBOutlet. | |
- (void)viewWillAppear:(BOOL)animated { | |
[super viewWillAppear:animated]; | |
[[NSNotificationCenter defaultCenter] addObserver:self | |
selector:@selector(adjustTableViewHeight:) | |
name:UIKeyboardDidShowNotification | |
object:nil]; | |
} | |
- (void)adjustTableViewHeight:(NSNotification*)notification { | |
CGRect keyboardFrame = [[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue]; | |
CGPoint keyboardOriginInView = [self.view.window convertPoint:keyboardFrame.origin toView:self.view]; | |
self.tableViewBottomConstraint.constant = CGRectGetHeight(self.view.frame) - keyboardOriginInView.y; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment