单击取消按钮后,搜索栏的框架发生了变化



我将我的搜索栏(左(和一个按钮(右(作为子视图添加到UIView.然后将UIView设置为TableHeaderView.但是在我结束搜索并单击取消按钮回到表格视图后,搜索栏将完全覆盖表格标题视图,并且看不到添加的按钮。我查看了图层,按钮仍然存在,只是被扩展的搜索栏覆盖。有人知道如何解决这个问题吗?提前感谢!

 self.searchController = [[UISearchController alloc]initWithSearchResultsController:nil];
self.searchController.searchResultsUpdater = self;
 UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, WinWidth, 40)]; 
self.searchController.searchBar.frame = CGRectMake(0, 0, WinWidth-50, 40); 
UIButton *filterBtn = [[UIButton alloc]initWithFrame:CGRectMake(WinWidth-30, 10, 20, 20)];
 filterBtn setBackgroundImage:[UIImage imageNamed:@"arrow_expend_down"] forState:UIControlStateNormal]; 
[view addSubview:self.searchController.searchBar]; [self.searchController.searchBar addSubview:filterBtn]; 
self.searchController.searchBar.barTintColor = [self colorWithRGB:0xf2f2f2 alpha:1]; 
[view addSubview:filterBtn];
 view.backgroundColor =self.searchController.searchBar.barTintColor; self.tableView.tableHeaderView = view;

尝试添加:tableView.tableHeaderView.contentMode = UIViewContentModeCenter;

试试这个

[self.searchController.searchBar sizeToFit];

相关内容

最新更新