OGeek|极客世界-中国程序员成长平台

标题: iOS - ScopeBar 与 TabBarController 中 UISearchController 中的 SearchBar 重叠 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 19:39
标题: iOS - ScopeBar 与 TabBarController 中 UISearchController 中的 SearchBar 重叠

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

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

插图: enter image description here

我已经尝试隐藏以下代码:

-(void)viewWillAppearBOOL)animated{
if(self.searchController.isActive){
    [self.searchController.searchBar setShowsScopeBar:TRUE];
}
}

-(void)viewDidDisappearBOOL)animated{
    if(self.searchController.isActive){
        [self.searchController.searchBar setShowsScopeBar:FALSE];
    }
}

无济于事。如果有人对此有窍门,我很乐意尝试一下。



Best Answer-推荐答案


每次生成 View 并返回该选项卡时以编程方式设置约束可能会通过将 UIScopeBar 与顶部保持固定距离来解决问题。您也可以尝试设置 UIScopeBar 和 UISearchBar 之间的约束。

NSLayoutConstraint *topSpaceConstraint = [NSLayoutConstraint constraintWithItem:self.view
                                                                             attribute:NSLayoutAttributeTop
                                                                             relatedBy:NSLayoutRelationEqual
                                                                                toItem:UIScopeBar 
                                                                             attribute:NSLayoutAttributeTop
                                                                            multiplier:1.0
                                                                              constant:5.0];
[self.view addConstraint:topSpaceConstraint];

如果这不起作用,您需要为我/这里的人提供更多代码来复制您遇到的错误。

关于iOS - ScopeBar 与 TabBarController 中 UISearchController 中的 SearchBar 重叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48391621/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4