简体   繁体   English

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

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

I am running into a peculiar issue regarding a scope bar shown under my UISearchBar. 关于UISearchBar下显示的范围栏,我遇到了一个特殊的问题。 Basically, the issue I previously had was that whenever my UISearchController was active and the user switched tabs, if he came back to the UIViewController containing the UISearchController, the background would turn back. 基本上,我以前遇到的问题是,每当我的UISearchController处于活动状态并且用户切换了选项卡时,如果他回到包含UISearchController的UIViewController,背景就会回头。 This issue was solved by embedding the UIViewController into a UINavigationController. 通过将UIViewController嵌入到UINavigationController中,可以解决此问题。

Now, a new issue has appeared. 现在,出现了一个新问题。 When I switch tabs with the UISearchController already active, when I switch back, the UIScopeBar is displayed on top of the UISearchBar. 当我在UISearchController已经激活的情况下切换选项卡时,当我切换回来时,UIScopeBar将显示在UISearchBar的顶部。 This can only be fixed by Canceling the search, and starting over. 这只能通过取消搜索并重新开始来解决。

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

I have tried hiding the following code: 我尝试隐藏以下代码:

-(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];
    }
}

To no avail. 无济于事。 If anybody has a trick for this one, I'd be glad to try it out. 如果有人对此有窍门,我很乐意尝试一下。

Setting a constraint programatically each time you generate the view and come back to that tab might do the trick by keeping the UIScopeBar at a fixed distance from the top. 每次生成视图并返回到该选项卡时,以编程方式设置约束都可以通过使UIScopeBar与顶部保持固定距离来解决问题。 You can also try setting the contraint between UIScopeBar and UISearchBar. 您也可以尝试设置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];

If this does not do the trick, you'll need to provide more code for me/people here to replicate the bug you're having. 如果这样做不能解决问题,则需要在此处为​​我/人们提供更多代码,以复制您遇到的错误。

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

相关问题 UISearchController:searchBar和scopeBar在第一次触摸事件时重叠 - UISearchController: searchBar and scopeBar overlap on first touch event UISearchController搜索栏与CollectionView重叠 - UISearchController searchbar overlaps CollectionView UISearchController:UITableView的Section索引与searchBar重叠 - UISearchController: Section Index of UITableView overlaps searchBar 如何使UISearchController中的范围栏始终在iOS Swift中可见? - How to make a scopebar in UISearchController always visible in Ios swift? iOS 13 如何在导航栏中隐藏UISearchController searchBar - iOS 13 How to hide UISearchController searchBar in navigationBar 如何在iOS 11中更改UISearchController SearchBar颜色 - How to change UISearchController SearchBar Colour in iOS 11 IOS8 UISearchController直接显示搜索栏 - IOS8 UISearchController display searchbar directly iOS-如何在没有UITableView的情况下将UISearchController.searchBar添加到控制器? - iOS - How to add UISearchController.searchBar to a controller without a UITableView? UISearchController不会解除iOS 8 Swift的搜索栏和重叠 - UISearchController won't dismiss searchbar and overlap for iOS 8 Swift 当UISearchController处于活动状态时,iOS 9 searchBar将从表头视图中消失 - iOS 9 searchBar disappears from table header view when UISearchController is active
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM