Broken UISearchBar animation embedded in NavigationItem
It looks like Apple still needs to iron out the use of the UISearchBar in the new large title style. If the UIViewController
you push to doesn't have its navigationItem.searchController
set, the animation works fine. When navigating between two instances of UIViewController
that both have a searchController set, you get the issue you describe where the height of the navigation bar jumps.
You can solve (work around) the problem by creating the UISearchController
every time viewDidAppear
gets called (instead of creating it in loadView
) and setting navigationItem.searchController
to nil on viewDidDisappear
.
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
DispatchQueue.main.async {
let stvc = UITableViewController()
stvc.tableView.dataSource = self
let sc = UISearchController(searchResultsController: stvc)
sc.searchResultsUpdater = self
self.navigationItem.searchController = sc
}
}
override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)
self.navigationItem.searchController = nil
}
The reason for the asynchronous dispatch is that when setting the navigationItem.searchController
inline in the viewDidAppear
method, an exception is raised:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Only one palette with a top boundary edge can be active outside of a transition. Current active palette is <_UINavigationControllerManagedSearchPalette: 0x7fad67117e80; frame = (0 116; 414 0); layer = <CALayer: 0x60400002c8e0>>'
I know this is only a work around, but hopefully this will help you for now, until Apple solves the issue with navigating between two view controllers that both have a UISearchController
set on their navigationItem
.
UISearchController / UINavigationBar shows broken animation when used within UINavigationController
Well, I finally found something very useful that I just couldn't find before asking my question:
Broken UISearchBar animation embedded in NavigationItem
Too bad this is known since iOS 11 and still not fixed.
Related Topics
"Cannot Connect to Itunes Store" In-App Purchases
How to Detect If iOS App Is Running in UI Testing Mode
How to Verify That I am Running on a Given Gcd Queue Without Using Dispatch_Get_Current_Queue()
Proper Use of Loadview and Viewdidload with Uiviewcontroller Without Nibs/Xibs
How to Programmatically Increase Uitableview Cell's Height in Iphone
Rotate a Uiview Around Its Center But Several Times
Programmatically Get a Storyboard Id
Uitableview with Two Custom Cells (Multiple Identifiers)
Fade Out Scrolling Uitextview Over Image
Ios5 Images Disappear When Scrolling with Webkit-Overflow-Scrolling: Touch
Xcode 5 Crashes -- Xcode Quit Unexpectedly
Repeating Local Notification Daily at a Set Time with Swift
Swift - Downloading Video with Downloadtaskwithurl
Auto Adjust Custom Uitableviewcell and Label in It to the Text