简体   繁体   中英

Height from keyboard to navigationbar

在此处输入图片说明

I need to create a tableview with the height from the keyboard y position to the navigation bar. The picture show a TableViewController where the textfields at the second section show the keyboard, I tried with the bounds and the scroll position but it doesn't work.

Anyone know how can I know this dimmensions ?

You can do this by changing UITableView bottom Constraint.

Pin your UITableView bottom to superView.Then register for UIKeyboardWillShowNotification / UIKeyboardWillHideNotification and get from NSNotification object keyboard frame and change bottom constraint constant, like this:

- (void)keyboardWillShow:(NSNotification *)notification {
    CGRect keyboardRect = [[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
    self.tableViewBottomConstraint.constant = CGRectGetHeight(keyboardRect);
   [self.view layoutIfNeeded];
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM