![](/img/trans.png)
[英]UISearchController: searchBar and scopeBar overlap on first touch event
[英]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.