Skip to content

Commit 154e1dc

Browse files
committed
Special cases to prevent any kind of animation for iOS <13. Doesn't solve the issue or keep the animation around, but allows us to have a very similar UX between iOS 12 and 13 while still using the system components and not reinventing the wheel - at least not too much.
1 parent ed3c8ac commit 154e1dc

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

SearchController/ViewController.swift

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,19 @@ class ViewController: UITableViewController {
1414
navigationItem.searchController = searchController
1515
}
1616

17+
override func viewDidLayoutSubviews() {
18+
defer { super.viewDidLayoutSubviews() }
19+
guard #available(iOS 13.0, *) else {
20+
searchController.hidesNavigationBarDuringPresentation = false
21+
// The cancel button has to go entirely, otherwise the scopes disappear _forever_
22+
// upon canceling - regardless of the setting above.
23+
searchController.searchBar.showsCancelButton = false
24+
// Have to make it active otherwise it overlaps with the cells of the UITableView.
25+
searchController.isActive = true
26+
return
27+
}
28+
}
29+
1730
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
1831
return 100
1932
}
@@ -26,7 +39,7 @@ class ViewController: UITableViewController {
2639

2740
// HAX: this hides and shows the scope bar appropriately to allow
2841
// the system animation of the search bar to complete properly.
29-
private var lastContentOffset: CGFloat = 0
42+
private var lastContentOffset = CGFloat(0)
3043
override func scrollViewDidScroll(_ scrollView: UIScrollView) {
3144
guard #available(iOS 13, *) else { return }
3245
let searchBar = searchController.searchBar

0 commit comments

Comments
 (0)