我使用带有tableView的UIViewController。 我已经设置了一个searchcontroller并将搜索栏嵌入到tableview标题中。 当我搜索它时,在tableview和它上面的uiview之间留下状态栏大小的间隙。 我意识到关于这个问题还有很多其他问题,但没有一个问题解决了这个问题。
以下是设置搜索栏的代码:
self.searchController = [[UISearchController alloc] initWithSearchResultsController:nil]; self.searchController.searchResultsUpdater = self; self.searchController.dimsBackgroundDuringPresentation = NO; self.searchController.hidesNavigationBarDuringPresentation = YES; self.searchController.searchBar.delegate = self; self.searchController.searchBar.backgroundImage = [UIImage new]; self.searchController.searchBar.backgroundColor = kBlueNavBarColor; self.searchController.searchBar.tintColor = [UIColor whiteColor]; self.tableView.tableHeaderView = self.searchController.searchBar; self.definesPresentationContext = YES;
Im using a UIViewController with a tableView. I've setup a searchcontroller and embed the searchbar into the tableview header. When i search it leaves a status bar sized gap between the tableview and the uiview above it. I realize there are a lot of other questions on SO about this but none of them solved this problem.
Here is the code for setting up the searchbar:
self.searchController = [[UISearchController alloc] initWithSearchResultsController:nil]; self.searchController.searchResultsUpdater = self; self.searchController.dimsBackgroundDuringPresentation = NO; self.searchController.hidesNavigationBarDuringPresentation = YES; self.searchController.searchBar.delegate = self; self.searchController.searchBar.backgroundImage = [UIImage new]; self.searchController.searchBar.backgroundColor = kBlueNavBarColor; self.searchController.searchBar.tintColor = [UIColor whiteColor]; self.tableView.tableHeaderView = self.searchController.searchBar; self.definesPresentationContext = YES;
最满意答案
在模态显示UIViewController时,我遇到了类似的问题。 导航栏太远了。 我调整了导航栏的大小,使其更宽一些。 如果这有帮助,请告诉我。 此问题始于iOS 7.您可能不需要检查版本。
float currentVersion = 7.0; if ([[[UIDevice currentDevice] systemVersion] floatValue] >= currentVersion) { // iOS 7 self.navBar.frame = CGRectMake(self.navBar.frame.origin.x, self.navBar.frame.origin.y, self.navBar.frame.size.width, 64); }I fixed it by changing the "top" auto layout anchor of the view that holds the segment controller from "super view" to "top layout guide". this moved the gap up to where the status bar is and changing the entire view's background color to the same color blue as the navbar made it seamless.
更多推荐
发布评论