我正在使用带有 tableView 的 UIViewController。我已经设置了一个搜索 Controller 并将搜索栏嵌入到 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;
最佳答案
以模态方式显示 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);
}
关于ios - TableView 标题中的 UISearchController 搜索栏留下状态栏大小的间隙,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37198442/