我在 XCode 5.0 中有一个 iOS 7 应用程序,它在点击搜索栏 (UISearchBar
) 时表现出一些奇怪的行为。
我的应用程序有一个导航 Controller 和一个标签栏 Controller 。这是我的 Main.Storyboard 的示例:
[Navigation Controller] -> [Tab Bar Controller] -> [Tab Item #1]
|
-------------> [Tab Item #2]
Each [] is a view controller
当我启动我的应用程序时,我看到带有 UISearchBar
的 Tab Item 1
,如下面的屏幕截图所示:
当我点击 UISearchBar
时,搜索栏向上滑动到屏幕顶部,但导航栏没有隐藏, View 也没有“向上滑动”。这会使应用看起来像这样:
当我从 Storyboard 中删除 Tab Bar Controller
并将 Navigation Controller
直接连接到 Tab Item #1
时,导航栏隐藏为预期。
如何在点击搜索栏时隐藏导航栏?有关我希望重现的功能示例,请单击默认 iOS7“电话”应用程序的“联系人”选项卡下的搜索栏。
最佳答案
对于 swift 开发者:
func searchBarTextDidBeginEditing(_ searchBar: UISearchBar) {
navigationController?.setNavigationBarHidden(true, animated: true)
}
func searchBarTextDidEndEditing(_ searchBar: UISearchBar) {
navigationController?.setNavigationBarHidden(false, animated: true)
}
这将在搜索栏处于事件状态时隐藏导航栏,并在搜索栏处于非事件状态时再次显示它。
关于ios - 激活搜索栏不会隐藏导航栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19348819/