2011-11-03 63 views
7

任何人都知道如何調整灰暗的黑色過度,一旦你點擊搜索欄?調整大小UISearchDisplayController暗灰色覆蓋

我有問題,當我點擊取消桌面將花費然後動畫消失。

我用這個來調整我的結果tableview。

-(void)searchDisplayController:(UISearchDisplayController *)controller didShowSearchResultsTableView:(UITableView *)tableView { 
    tableView.frame =fTableView.frame;//CGRectMake(26, 100, 280, 310); //fTableView.frame; 
    tableView.backgroundColor = [UIColor colorWithRed:243.0/255.0 green:236.0/255.0 blue:212.0/255.0 alpha:1]; 
} 

當點擊搜索欄時,灰色覆蓋層已滿而不是我定義的大小。

enter image description here

enter image description here

點擊時取消按鈕,視圖將花費回來。 enter image description here

+1

此答案從湯姆斯威夫特解決了我的問題:http://stackoverflow.com/a/4128659/675486 –

回答

1

我以爲searchDisplayController擁有一個單獨的tableview,所以我的猜測是你需要調整一個。沿線的

東西:<yourSearchViewController>.view.frame =self.tableView.frame;

,或者如果你沒有它作爲類變量,在接收它作爲參數的方法,如:

-(void)searchDisplayController:(UISearchDisplayController *)controller didShowSearchResultsTableView:(UITableView *)tableView { 
    controller.view.frame = self.tableView.frame; 
    tableView.backgroundColor = [UIColor colorWithRed:243.0/255.0 green:236.0/255.0 blue:212.0/255.0 alpha:1]; 
} 

Alternativily你可能想子類並在本地覆蓋其視圖屬性。

希望這會有所幫助!

+0

沒有什麼像'UISearchDisplayController'中的'view'一樣。您的解決方案會給出錯誤。 – thesummersign

+0

這表明你應該尋找什麼。如果您再花幾分鐘時間查看控制器屬性,您會注意到_does_具有名爲'searchResultsTableView'的特定視圖。來源:http://developer.apple.com/library/ios/#documentation/uikit/reference/UISearchDisplayController_Class/Reference/Reference.html – Wolfert

+0

我經歷了控制器的'.h'文件,並找到了'UIView * _view',但它似乎沒有暴露。 – thesummersign

0

UISearchDisplayController確實擁有自己的tableview,不容易馴服。 我遇到過這樣的事情,我仍然在尋找更好的解決方案。

-(void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller 
{ 
    [controller.searchResultsTableView setDelegate:self]; 
    CGFloat gr = 12.0; 
    controller.searchResultsTableView.backgroundColor = [UIColor colorWithRed:gr green:gr blue:gr alpha:0.0]; 
    [controller.searchResultsTableView setSeparatorStyle:UITableViewCellSelectionStyleNone]; 
    CGRect searchTableFrame = CGRectMake(7, 105, 305, 292); 
    [controller.searchResultsTableView setFrame:searchTableFrame]; 
} 

上面的代碼確實將背景設置爲透明,但似乎默默地忽略了幀的大小。

編輯:解決 我找到了強大的解決方案,這here。 這救了我的命。

+0

另外我還使用了自定義單元格來模擬外觀,就好像它適合所需的寬度。 – thesummersign

10

我組合了幾個答案以移動暗淡的覆蓋幀。

1:覆蓋UISearchDisplayController類

@interface MySearchController : UISearchDisplayController 

2:覆蓋SETACTIVE功能

- (void)setActive:(BOOL)visible animated:(BOOL)animated 
{ 
[super setActive: visible animated: animated]; 

//move the dimming part down 
for (UIView *subview in self.searchContentsController.view.subviews) { 
    //NSLog(@"%@", NSStringFromClass([subview class])); 
    if ([subview isKindOfClass:NSClassFromString(@"UISearchDisplayControllerContainerView")]) 
    { 
     CGRect frame = subview.frame; 
     frame.origin.y += 10; 
     subview.frame = frame; 
    } 
} 

} 

3:改變從UISearchDisplayController的XIB /故事板搜索顯示控制器 MySearchController

+0

niiiice。爲我工作 – MrTristan

+0

使用它來改變寬度。謝謝!!! – AlexanderZ

+0

這是解決此問題的最佳解決方案。謝謝! –

相關問題