gpt4 book ai didi

ios - 激活搜索栏不会隐藏导航栏

转载 作者:可可西里 更新时间:2023-11-01 03:28:48 24 4
gpt4 key购买 nike

我在 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

当我启动我的应用程序时,我看到带有 UISearchBarTab Item 1,如下面的屏幕截图所示:

one

当我点击 UISearchBar 时,搜索栏向上滑动到屏幕顶部,但导航栏没有隐藏, View 也没有“向上滑动”。这会使应用看起来像这样:

two

当我从 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/

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