UISearchController发布iOS8和iOS9

时间:2015-10-12 06:59:21

标签: ios uinavigationbar uisearchcontroller

我遇到了一个问题,UISearchControllersearchBar设置为navigationBar的动画,使statusBar透明且与{searchBar颜色不同1}},如下所示:

enter image description here

我搜索了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解决此问题的任何建议吗?

0 个答案:

没有答案