[英]How can I mimic safari's search bar UI/animations in Swift?
I am attempting to mimic the search bar behavior below in iOS Safari on my current app: 我正在尝试在当前应用程序的iOS Safari中模仿下面的搜索栏行为:
I mainly want the navigation bar to scroll up to a very small version when the user scrolls on the content and comes back when they scroll back up. 我主要希望导航栏在用户滚动内容时向上滚动至很小的版本,并在用户向上滚动时返回。
I've tried using scrollViewDidScroll but I cannot seem to get it to mimic that behavior. 我试过使用scrollViewDidScroll,但似乎无法模仿它。 I'm unsure if I am adding the search bar correctly to the navigation bar.
我不确定是否将搜索栏正确添加到导航栏中。
let searchBar: UISearchBar = {
let sb = UISearchBar()
sb.autocapitalizationType = .none
sb.autocorrectionType = .no
sb.keyboardAppearance = UIKeyboardAppearance.default
sb.placeholder = "Search"
return sb
}()
fileprivate func setupNav() {
//Basic Setup
navigationController?.navigationBar.isTranslucent = true
navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
//Search Bar
searchBar.sizeToFit()
navigationItem.titleView = searchBar
}
func scrollViewDidScroll(_ scrollView: UIScrollView) {
//Implement
}
let searchController = UISearchController(searchResultsController: nil)
searchController.dimsBackgroundDuringPresentation = false
searchController.searchBar.placeholder = "Search"
searchController.searchResultsUpdater = self
navigationItem.searchController = searchController
definesPresentationContext = true
Put your SearchController
in the Navigation Item instead. 将您的
SearchController
放在导航项中。 This will add collapsable SearchBar
. 这将添加可折叠的
SearchBar
。 Additionally you can try with Navigation Item Prompt
for very small title on top. 另外,您可以尝试使用导航项
Prompt
在顶部显示非常小的标题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.