tableview标题中的UISearchController搜索栏会留下状态栏大小的差距(UISearchController searchbar in a tableview header lea

编程入门 行业动态 更新时间:2024-10-10 04:19:52
tableview标题中的UISearchController搜索栏会留下状态栏大小的差距(UISearchController searchbar in a tableview header leaves status bar sized gap)

我使用带有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.

更多推荐

本文发布于:2023-08-07 17:40:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1465298.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:状态栏   差距   大小   标题   tableview

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!