我遇到了一个问题,UISearchController
将searchBar
设置为navigationBar
的动画,使statusBar
透明且与{searchBar
颜色不同1}},如下所示:
我搜索了SO,以下解决方案受到this question
的启发- (void)willPresentSearchController:(UISearchController *)searchController {
self.navigationController.navigationBar.translucent = YES;
}
- (void)willDismissSearchController:(UISearchController *)searchController {
self.navigationController.navigationBar.translucent = NO;
}
解决了iOS9的问题,但不适用于iOS8 。我试过设置
self.extendedLayoutIncludesOpaqueBars = YES;
但没有效果。另外,设置
self.edgesForExtendedLayout = UIRectEdgeAll;
隐藏searchBar
下的初始navigationBar
,因此我无法使用它。
以下是我在不透明UISearchController
下发起UINavigationBar
的代码:
UITableViewController *searchResultsController = [[UITableViewController alloc] initWithStyle:UITableViewStylePlain];
searchResultsController.tableView.dataSource = self;
searchResultsController.tableView.delegate = self;
self.searchController = [[UISearchController alloc] initWithSearchResultsController:searchResultsController];
self.searchController.delegate = self;
self.searchController.searchResultsUpdater = self;
self.searchController.searchBar.delegate = self;
self.searchController.searchBar.barTintColor = [UIColor whiteColor];
self.searchController.searchBar.frame = CGRectMake(0.0, 0.0, self.view.frame.size.width, 44.0); // Required for iOS8, not iOS9 though
[self.view addSubview:self.searchController.searchBar];
有关如何为iOS8解决此问题的任何建议吗?