9

I am running into a small problem, I implemented the new iOS 11's style search bar in my app, and I noticed that it disappeared with a slightly different animation from the one in Messages for example. It's faster and less smooth.

Anyone has ever stumble upon this "problem" ?

Here is the code I use :

searchController.searchResultsUpdater = self
searchController.obscuresBackgroundDuringPresentation = false
searchController.searchBar.delegate = self

if #available(iOS 11.0, *) {
    navigationItem.searchController = searchController
} else {
    tableView.tableHeaderView = searchController.searchBar
    searchController.searchBar.barTintColor = .white
    searchController.searchBar.layer.borderColor = UIColor.white.cgColor
    searchController.searchBar.layer.borderWidth = 1
}
definesPresentationContext = true
searchController.searchBar.placeholder = "all_search".localized

EDIT: enter image description here

I don't know if it will help you, but I am scrolling at a normal pace . Thanks

Nicolas Charvoz
  • 1,509
  • 15
  • 41

4 Answers4

3

Adding

self.extendedLayoutIncludesOpaqueBars = true

to my viewDidLoad solved the issue, your navigation bar must not be translucent and note that extendedLayoutIncludesOpaqueBars = true is being attributed to my main view which holds the tableview.

Douglas Pfeifer
  • 147
  • 1
  • 8
  • When customizing a navigation bar so its background is opaque, the layout of the view controller is inset so the top of the view ends at the bottom of the navigation bar. (It's not visible under the bar, so it's clipped) Extending the layout extends the travel of the scroll view, which extends the duration of the animation. – Scott Ahten Jul 03 '19 at 21:18
1

This happens when your table view doesn't go all the way to the top of the view. Make sure your table view is "behind" the navigation bar and uses extended edges and extend under opaque edges if your navigation bar is opaque.

  • I am having this issue, but since my navbar is not translucent I cannot have my tableview under the nav bar. any ideas? – Jerland2 May 26 '18 at 23:05
0

Try this, it fixes it for me. I used a different UIViewController as the searchResultsUpdater and just set extendedLayoutIncludesOpaqueBars as true.

searchResultsUpdater.extendedLayoutIncludesOpaqueBars = true
searchController.searchResultsUpdater = searchResultsUpdater
AWillian
  • 53
  • 1
  • 7
-1
UIView.animate(withDuration: 1, animations: { 
//your codes to implement
}, completion: nil)

change withDuration: in seconds

Kisoth Srinathan
  • 115
  • 2
  • 10
  • 1
    The problem is that I don't handle the animation, it's a native animation in iOS 11, so I don't have anything to code about it . – Nicolas Charvoz Mar 09 '18 at 13:35