Why does search bar hides abruptly without animation when swiped back to unwind segue (Swift)?

In my Swift 5 app, I have a view controller embedded in a navigation controller. The navigation bar has a search bar. The view controller has a table view. Selecting the table view cells, pushes a new view controller which also has a search bar in its navigation bar.

If I try to swipe back on the second view controller to pop it, the search bar abruptly vanishes instead of animating and hiding.

https://gifyu.com/image/EYqH

Also, notice that when swipe back is cancelled (swipe left and then right) the search bar finally reappears with a line on top of it.

I tried to debug the view hierarchy to find that the unwanted line is _UIBarBackground’s UIImageView of height 0.5. I have no idea why this appeared.

This is how I’m using the search controller in the second VC:

Inside the VC’s viewDidLoad:

Everything is working fine for the search bar of the first VC. The code for seach bar inside the viewDidLoad of first VC is also same as above. This is how the search bar animated and hides when swiped back on the first VC:

https://gifyu.com/image/EYqc

I do not understand where I’m going wrong. Any suggestions/help would be appreciated. Thanks in advance.

If you don't show the code in the 2 situations, one that work one that doesn't, it is pretty hard to guess…

Have defined animations in both cases ? Are they different ?

I've the following code inside my viewDidLoad for searchController in both the cases:


searchController = UISearchController(searchResultsController: nil)
searchController.searchResultsUpdater = self
searchController.obscuresBackgroundDuringPresentation = false
searchController.searchBar.placeholder = "Search"
searchController.searchBar.becomeFirstResponder()
searchController.searchBar.tintColor = Constants.primaryThemeColor
navigationItem.searchController = searchController
definesPresentationContext = true
navigationItem.hidesSearchBarWhenScrolling = false


I have taken https://www.raywenderlich.com/472-uisearchcontroller-tutorial-getting-started as my reference.

Why does search bar hides abruptly without animation when swiped back to unwind segue (Swift)?
 
 
Q