在tableview标题中的UISearchController搜索栏留下状态栏大小的差距

问题描述:

Im使用带有tableView的UIViewController。我已经设置了一个searchcontroller并将搜索栏嵌入到tableview标题中。当我搜索它时,会在桌面视图和其上方的视图之间留下状态栏大小的差距。我意识到关于这个问题还有很多其他问题,但他们都没有解决这个问题。在tableview标题中的UISearchController搜索栏留下状态栏大小的差距

这里是设置搜索栏的代码:

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; 

enter image description here enter image description here Here is the layout of the view:

我通过改变“顶部”自动布局保持从“超级视图”到“顶部布局引导段控制器的视图的锚固定它”。这将间隙拉到了状态栏的位置,并将整个视图的背景颜色更改为与导航栏无缝相同的蓝色。

呈现出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); 
    } 
+0

谢谢,这是行不通的。 –

+0

当您调整导航栏的大小时,会发生什么情况,灰色仍然稍微低一点? – Yan

+0

我想通了,看到我的答案。谢谢。 –

禁用大小类并定义自定义自动调整。请参考以下图片: -

UITableView Autoresize:- 

Autoresizing for UITableView

UISearchBar Autoresize:- 

UISearchBarController autoresize

注:: - 你CA在禁用自动布局和大小类时,请参阅上面的大小检查器。

+0

关闭整个故事板的自动布局来解决这个问题并不是真的可行。 –

+0

是的,我可以理解。 – MShah

enter image description here

取消选中调整滚动查看插图

+0

试过这个,没有工作 –