As you can see, my UITableView
's scroll is maximum down, but my table is not fully visible. Why? I use UITableViewController
Good alternative to Ortwin's answer is to use keyboardDismissMode
property of UIScrollView
:
tableView.keyboardDismissMode = .OnDrag
Swift 4.1
tableView.keyboardDismissMode = .onDrag
I recommend to simply hide the keyboard as soon as the user starts scrolling. Apple implements this behavior in their own apps. To do that, add in your table view controller:
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
[self.searchBar resignFirstResponder];
}
This requires a searchBar
property that is populated with the search bar.
using notifications might be easiest way to get the keyboard height as i commented set contentInset
property to scroll the tableview above the keyboard, once it hides set to zero insects,
- (void)viewWillAppear:(BOOL)animate
{
[super viewWillAppear:animate];
// Do any additional setup after loading the view.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardShown:)
name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardHidden:)
name:UIKeyboardWillHideNotification object:nil];
}
- (void)viewWillDisappear:(BOOL)animated
{
//remove notifications
}
- (void)keyboardShown:(NSNotification*)aNotification
{
NSDictionary* info = [aNotification userInfo];
CGRect keyboardRect = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
float height = keyboardRect.size.height;
tableView.contentInset = UIEdgeInsetsMake(10, 0, height, 0);
}
- (void)keyboardHidden:(NSNotification*)aNotification
{
[UIView animateWithDuration:0.2 animations:^{
table.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);
}];
}
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.