菜鸟教程小白 发表于 2022-12-11 19:39:12

iOS - ScopeBar 与 TabBarController 中 UISearchController 中的 SearchBar 重叠


                                            <p><p>我遇到了一个关于我的 UISearchBar 下显示的范围栏的特殊问题。
基本上,我之前遇到的问题是,每当我的 UISearchController 处于事件状态并且用户切换选项卡时,如果他回到包含 UISearchController 的 UIViewController,背景就会返回。
通过将 UIViewController 嵌入 UINavigationController 解决了这个问题。</p>

<p>现在,出现了一个新问题。当我在 UISearchController 已经处于事件状态的情况下切换选项卡时,当我切换回来时,UIScopeBar 会显示在 UISearchBar 的顶部。这只能通过取消搜索并重新开始来解决。</p>

<p>插图:
<a href="/image/1gMFD.png" rel="noreferrer noopener nofollow"><img src="/image/1gMFD.png" alt="enter image description here"/></a> </p>

<p>我已经尝试隐藏以下代码:</p>

<pre><code>-(void)viewWillAppear:(BOOL)animated{
if(self.searchController.isActive){
    ;
}
}

-(void)viewDidDisappear:(BOOL)animated{
    if(self.searchController.isActive){
      ;
    }
}
</code></pre>

<p>无济于事。如果有人对此有窍门,我很乐意尝试一下。</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>每次生成 View 并返回该选项卡时以编程方式设置约束可能会通过将 UIScopeBar 与顶部保持固定距离来解决问题。您也可以尝试设置 UIScopeBar 和 UISearchBar 之间的约束。</p>

<pre><code>NSLayoutConstraint *topSpaceConstraint = [NSLayoutConstraint constraintWithItem:self.view
                                                                           attribute:NSLayoutAttributeTop
                                                                           relatedBy:NSLayoutRelationEqual
                                                                              toItem:UIScopeBar
                                                                           attribute:NSLayoutAttributeTop
                                                                            multiplier:1.0
                                                                              constant:5.0];
;
</code></pre>

<p>如果这不起作用,您需要为我/这里的人提供更多代码来复制您遇到的错误。</p></p>
                                   
                                                <p style="font-size: 20px;">关于iOS - ScopeBar 与 TabBarController 中 UISearchController 中的 SearchBar 重叠,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/48391621/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/48391621/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: iOS - ScopeBar 与 TabBarController 中 UISearchController 中的 SearchBar 重叠