Swift : show searchbar when scroll up and hide it when scroll down
Asked Answered
H

1

8

I am new to Ios develpomment, I added a Searchbar into the navigation item What I would like to implement is when I scroll Up the tableview I want to hide the Searchbar and when show it when I scroll down

Like safari effect on iPAD /Iphone where the address bar is hiding when scrolling Down and showing when scrolling Up

  let searchController = UISearchController(searchResultsController: nil)
  searchController.searchResultsUpdater = self
  searchController.obscuresBackgroundDuringPresentation = false
  navigationItem.searchController = searchController
  definesPresentationContext = true 

thank your for helping.

Haro answered 7/3, 2018 at 11:31 Comment(0)
A
11

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://mcmap.net/q/237550/-show-search-bar-in-navigation-bar-without-scrolling-on-ios-11

Azaleah answered 7/3, 2018 at 11:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.