Setup
A simple view controller with a UISearchController set in the navigation item to use iOS 11's search functionality in the search bar.
Any view with it's top constrained to the SafeArea.Top
Problem
When presenting the search controller, the navigation bar is animated because of it's size change, but the constraint to top area does not follow the animation.
If anyone have an idea of what I can do (right now I guess my only choice is to disable the hidesNavigationBarDuringPresentation
to avoid the animation at all)
See example below where I activated the slow animations for easier understanding:
You could animate the constraint change with UIView.animate. Since your constraint is based on the view's safe area, the viewSafeAreaInsetsDidChange
method could alert you of changes in the constraint value :
override func viewSafeAreaInsetsDidChange() {
UIView.animate(withDuration: 1) {
self.view.layoutIfNeeded()
}
}
I faced the same issue on iOS 13.3. This code fixed it.
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
navigationController?.view.backgroundColor = .white
navigationController?.navigationBar.isTranslucent = false
}
If you disable isTranslucent on viewDidLoad, searchBar would be hidden when the view appears. You can also utilize navigationItem.hideSearchBarWhenScrolling to avoid putting the code in viewDidAppear.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With