gpt4 book ai didi

ios - UISearchBar - 如何防止在点击取消按钮时关闭 scopeBar?

转载 作者:可可西里 更新时间:2023-11-01 06:17:27 28 4
gpt4 key购买 nike

我希望我的 UISearchBar 的 scopeButtons 始终保持可见,但即使我设置了 searchBar.showsScopeBar = YES',按钮仍然被关闭如果我开始搜索然后取消搜索,会出现一个动画。

有什么方法可以防止在取消搜索时 scopeBar 动画消失?

最佳答案

由于范围栏仅在 UISearchController 处于事件状态时使用,因此我以不同的方式解决了这个问题。

我立即激活 UISearchController

override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
// Immediately activating the searchController keeps scope bar permanently visible
searchController.isActive = true
// Tapping the cancel button triggers this method, which quickly toggles the scope bar
// But the cancel button isn't needed anyway, so hiding it solves the problem
searchController.searchBar.showsCancelButton = false
}

但现在 UISearchController 始终处于事件状态,默认情况下 UINavigationBar 处于隐藏状态,这可能不是您想要的。为了解决这个问题,我阻止它隐藏在 viewDidLoad

searchController.hidesNavigationBarDuringPresentation = false

这种方法意味着我根本不需要使用 showsScopeBar,因为它在 UISearchController 处于事件状态时始终可见。

关于ios - UISearchBar - 如何防止在点击取消按钮时关闭 scopeBar?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6780107/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com