• <legend id='SzXrs'><style id='SzXrs'><dir id='SzXrs'><q id='SzXrs'></q></dir></style></legend>
    <i id='SzXrs'><tr id='SzXrs'><dt id='SzXrs'><q id='SzXrs'><span id='SzXrs'><b id='SzXrs'><form id='SzXrs'><ins id='SzXrs'></ins><ul id='SzXrs'></ul><sub id='SzXrs'></sub></form><legend id='SzXrs'></legend><bdo id='SzXrs'><pre id='SzXrs'><center id='SzXrs'></center></pre></bdo></b><th id='SzXrs'></th></span></q></dt></tr></i><div id='SzXrs'><tfoot id='SzXrs'></tfoot><dl id='SzXrs'><fieldset id='SzXrs'></fieldset></dl></div>
  • <small id='SzXrs'></small><noframes id='SzXrs'>

      1. <tfoot id='SzXrs'></tfoot>
        • <bdo id='SzXrs'></bdo><ul id='SzXrs'></ul>

        如何在 iOS 8 中使用 UISearchController,其中 UISearchBar 在我的导航栏中并且有范围

        时间:2023-05-17

          <tbody id='tvid8'></tbody>
          <bdo id='tvid8'></bdo><ul id='tvid8'></ul>
        • <small id='tvid8'></small><noframes id='tvid8'>

          <tfoot id='tvid8'></tfoot>

            1. <legend id='tvid8'><style id='tvid8'><dir id='tvid8'><q id='tvid8'></q></dir></style></legend>
                  <i id='tvid8'><tr id='tvid8'><dt id='tvid8'><q id='tvid8'><span id='tvid8'><b id='tvid8'><form id='tvid8'><ins id='tvid8'></ins><ul id='tvid8'></ul><sub id='tvid8'></sub></form><legend id='tvid8'></legend><bdo id='tvid8'><pre id='tvid8'><center id='tvid8'></center></pre></bdo></b><th id='tvid8'></th></span></q></dt></tr></i><div id='tvid8'><tfoot id='tvid8'></tfoot><dl id='tvid8'><fieldset id='tvid8'></fieldset></dl></div>
                  本文介绍了如何在 iOS 8 中使用 UISearchController,其中 UISearchBar 在我的导航栏中并且有范围按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我正在尝试使用来自 iOS 8 的新 UISearchController,并将其 UISearchBar 嵌入到我的 UINavigationBar 中.这很容易做到,如下所示:

                  I'm trying to use the new UISearchController from iOS 8, and embed its UISearchBar in my UINavigationBar. That's easily done as follows:

                  searchController = UISearchController(searchResultsController: nil)
                  searchController.searchResultsUpdater = self
                  searchController.delegate = self
                  searchController.searchBar.delegate = self
                  searchController.dimsBackgroundDuringPresentation = false
                  searchController.hidesNavigationBarDuringPresentation = false
                  navigationItem.titleView = searchController.searchBar
                  

                  但是当我添加范围按钮时:

                  But when I add the scope buttons:

                  searchController.searchBar.showsScopeBar = true
                  searchController.searchBar.scopeButtonTitles = ["Posts, Users, Subreddits"]
                  

                  它在UISearchBar后面添加了按钮,显然看起来很奇怪.

                  It adds the buttons behind the UISearchBar and obviously looks very odd.

                  我应该怎么做?

                  推荐答案

                  你遇到了一个设计问题",当 searchControllerscopeBar 应该被隐藏代码> 未激活.

                  You're bumping into a "design issue" where the scopeBar is expected to be hidden when the searchController is not active.

                  范围栏按钮出现在搜索栏的后面(下方),因为当搜索栏变为活动状态并在导航栏中自行设置动画时,这是它们的位置.

                  The scope bar buttons appear behind (underneath) the search bar since that's their location when the search bar becomes active and animates itself up into the navigation bar.

                  当搜索未激活时,可见的范围栏会占用屏幕空间,分散内容的注意力,并使用户感到困惑(因为范围按钮没有要过滤的结果).

                  由于您的 searchBar 已经位于 titleView 中,因此不会出现显示范围栏的(导航和搜索)栏动画.

                  Since your searchBar is already located in the titleView, the (navigation and search) bar animation that reveals the scope bar doesn't occur.

                  • 最简单的选项是找到下面的搜索栏导航栏,并让 searchBar 动画到标题激活时的区域.导航栏将为其高度设置动画,腾出空间来包含隐藏的范围栏.这都会由搜索控制器处理.
                  • 第二个选项几乎同样简单,就是使用搜索栏按钮图标,它将使 searchBarscopeBar 向下移动到查看导航栏.

                  • The easiest option is to locate the search bar below the navigation bar, and let the searchBar animate up into the title area when activated. The navigation bar will animate its height, making room to include the scope bar that was hidden. This will all be handled by the search controller.
                  • The second option, almost as easy, is to use a Search bar button icon, which will animate the searchBar and scopeBar down into view over the navigation bar.

                  - (IBAction)searchButtonClicked:(UIBarButtonItem *)__unused sender {
                      self.searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
                      self.searchController.searchResultsUpdater = self;
                      self.searchController.hidesNavigationBarDuringPresentation = NO;
                      self.searchController.dimsBackgroundDuringPresentation = NO;
                      self.definesPresentationContext = YES;
                      self.searchController.searchBar.scopeButtonTitles = @[@"Posts", @"Users", @"Subreddits"];
                      [self presentViewController:self.searchController animated:YES completion:nil];
                  }

                • 如果你想让 searchBar 留在 titleView 中,一个动画做你想做的事不是内置的.你必须自己动手处理导航栏高度变化并显示您自己的代码范围栏(或挂钩到内部,并动画内置scopeBar 向下并进入视图).

                • If you want the searchBar to remain in the titleView, an animation to do what you want is not built in. You'll have to roll your own code to handle the navigationBar height change and display your own scope bar (or hook into the internals, and animate the built-in scopeBar down and into view).

                  如果你很幸运,其他人已经编写了 willPresentSearchController: 代码来处理你想要的转换.

                  If you're fortunate, someone else has written willPresentSearchController: code to handle the transition you want.

                  如果您希望始终看到 searchBarscopeBar,您可能不得不放弃使用内置的 scopeBar,并将其替换为用户将始终看到的 UISegmentedControl,即使搜索控制器未处于活动状态.

                  If you want to always see a searchBar and scopeBar, you'll probably have to ditch using the built-in scopeBar, and replace it with a UISegmentedControl which the user will always see, even when the search controller is not active.

                  更新:

                  此答案建议子类化 UISearchController 以更改其 searchBar 的高度.

                  This answer suggested subclassing UISearchController to change its searchBar's height.

                  这篇关于如何在 iOS 8 中使用 UISearchController,其中 UISearchBar 在我的导航栏中并且有范围按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                • 上一篇:Swift – 在 App Delegate 中实例化没有故事板的导航控制器 下一篇:iPhone向左推视图控制器

                  相关文章

                    <bdo id='Ok5nM'></bdo><ul id='Ok5nM'></ul>

                      <tfoot id='Ok5nM'></tfoot>

                    1. <i id='Ok5nM'><tr id='Ok5nM'><dt id='Ok5nM'><q id='Ok5nM'><span id='Ok5nM'><b id='Ok5nM'><form id='Ok5nM'><ins id='Ok5nM'></ins><ul id='Ok5nM'></ul><sub id='Ok5nM'></sub></form><legend id='Ok5nM'></legend><bdo id='Ok5nM'><pre id='Ok5nM'><center id='Ok5nM'></center></pre></bdo></b><th id='Ok5nM'></th></span></q></dt></tr></i><div id='Ok5nM'><tfoot id='Ok5nM'></tfoot><dl id='Ok5nM'><fieldset id='Ok5nM'></fieldset></dl></div>
                      <legend id='Ok5nM'><style id='Ok5nM'><dir id='Ok5nM'><q id='Ok5nM'></q></dir></style></legend>

                      <small id='Ok5nM'></small><noframes id='Ok5nM'>