Swift : show searchbar when scroll up and hide it when scroll down

ε祈祈猫儿з 提交于 2019-12-10 15:18:41

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/49150857/swift-show-searchbar-when-scroll-up-and-hide-it-when-scroll-down

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!