本文介绍了表格视图标题中的 UISearchController 搜索栏留下状态栏大小的差距的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用带有 tableView 的 UIViewController.我已经设置了一个搜索控制器并将搜索栏嵌入到 tableview 标题中.当我搜索时,它会在 tableview 和上面的 uiview 之间留下一个状态栏大小的间隙.我意识到在 SO 上还有很多其他问题,但没有一个解决了这个问题.

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;

推荐答案

我通过将包含段控制器的视图的顶部"自动布局锚点从超级视图"更改为顶部布局指南"来修复它.这将间隙移到状态栏所在的位置,并将整个视图的背景颜色更改为与导航栏相同的蓝色,使其无缝.

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.

这篇关于表格视图标题中的 UISearchController 搜索栏留下状态栏大小的差距的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 02:32