Show search bar in navigation bar without scrolling on iOS 11
The following makes the search bar visible at first, then allows it to hide when scrolling:
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
if #available(iOS 11.0, *) {
navigationItem.hidesSearchBarWhenScrolling = false
}
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
if #available(iOS 11.0, *) {
navigationItem.hidesSearchBarWhenScrolling = true
}
}
Using isActive
didn't do what I wanted, it makes the search bar active (showing cancel button, etc.), when all I want is for it to be visible.
Swift : show searchbar when scroll up and hide it when scroll down
All you need to do is to hide and display your search bar when you start scrolling so for that you need to override the didBeginScrolling (check the exact name ) and add this code accordingly
navigationItem.hidesSearchBarWhenScrolling = false
more info is here https://stackoverflow.com/a/46352230/5123516
Related Topics
How to Integrate Nsurlconnection with Uiprogressview
How to Change Color of Uitableviewcell When Selecting
Open Specific View When Opening App from Notification
Uiwebview Random Crash at [Uiviewanimationstate Release]: Message Sent to Deallocated Instance
How to Get Uiviewcontroller of a Uiview's Superview in iOS
Implementing Auto Layout for Views Generated Programmatically
Libmobilegestalt Mobilegestaltsupport.M:153 Mobilegestalt.C:550 Xcode Console
Border Around Uitableview Section
Swift iOS Add Infinite Scroll Pagination to Uitableview
Fbsopenapplicationerrordomain Code =4 Error
How to Know If Nsassert Is Disabled in Release Builds
Ipad: Drag a Uitableviewcell from One Uitableviewcontroller and Drop It into Another
How to Downscale a Uiimage in iOS by the Data Size
iOS 11 Uisearchbar in Uinavigationbar
Corelocation Heading Base on Back Camera (Augmented Reality)