I've recently added a UISearchController to my table view and I'm experiencing an animation issue. When the search bar is tapped and becomes active, the table view jumps up to meet the search controller's new (active) position. The problem with this is that the search controller animates to this new position but the table view doesn't so it's quite jarring. Here is a video of the issue.
The top constraint on the table view is set to the view controller's safe area. Below is the code I have written for configuring the search controller:
- (void)configureSearchController { UISearchController *searchController = [[UISearchController alloc] initWithSearchResultsController:nil]; searchController.searchResultsUpdater = self; searchController.obscuresBackgroundDuringPresentation = NO; searchController.searchBar.placeholder = @"Search for any cryptocurrency"; self.searchController = searchController; if (@available(iOS 11.0, *)) { self.navigationItem.searchController = searchController; } else { self.navigationItem.titleView = searchController.searchBar; } self.definesPresentationContext = YES; }
Does anyone have any suggestions as to how I can make the transition smooth? Ideally I would like the table view to move up at the same rate as the search controller as this is the default behaviour throughout iOS.
2 Answers
Answers 1
I think, the problem with top constraint to safe area. SearchController couldn't update tableview frame while updating it's navigation bar position. So If you could set the tableview's top constraint to superview, animation could be smooth. Set your tableview constraints as below:
Hopefully, It will work!
Answers 2
From the video I believe the table view is not extending beneath the navigation bar. You can probably avoid that jump if you actually allow it to do so.
You should also set
tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentAutomatic
So that its contentInsets are automatically adjusted.
0 comments:
Post a Comment