[英]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.
这只能通过取消搜索并重新开始来解决。
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.