繁体   English   中英

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

[英]iOS - ScopeBar overlaps SearchBar in UISearchController in TabBarController

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

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

插图: 在此处输入图片说明

我尝试隐藏以下代码:

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

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

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

每次生成视图并返回到该选项卡时,以编程方式设置约束都可以通过使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];

如果这样做不能解决问题,则需要在此处为​​我/人们提供更多代码,以复制您遇到的错误。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM