0

I have a search bar inside a navigation And I want it to shrink into navigation when it scrolls like Safari. Just like the photos below image what I need

this is my code but

class ViewController: UIViewController, UITextFieldDelegate, WKNavigationDelegate, WKUIDelegate , UISearchBarDelegate {
var searchBar:UISearchBar = UISearchBar(frame: CGRect(x: 0, y: 0, width: 440, height: 40))
override func viewDidLoad() {
    super.viewDidLoad()
    searchBar.delegate = self
    searchBar.placeholder = "Search or enter website name"
    self.navigationItem.titleView = searchBar
    }
}
  • [here](https://stackoverflow.com/questions/40667985/how-to-hide-the-navigation-bar-and-toolbar-as-scroll-down-swift-like-mybridge) you can find several solutions to this problem – Vadim Nikolaev Dec 18 '19 at 11:40

1 Answers1

0

Have you looked into using UISearchController instead?

You can set the hidesSearchBarWhenScrolling property to true to automatically hide the search bar as you scroll.

https://developer.apple.com/documentation/uikit/uisearchcontroller

adamfootdev
  • 1,149
  • 10
  • 15