ios - TableView 标题中的 UISearchController 搜索栏留下状态栏大小的间隙

标签 ios objective-c uitableview

我正在使用带有 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;

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);
    }

关于ios - TableView 标题中的 UISearchController 搜索栏留下状态栏大小的间隙,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37198442/

相关文章:

ios - 观察NSArray中NSDictionary的值变化

ios - UIView 是如何保护框架属性成员的呢?

ios - 如何使图像始终显示正确的方向?

ios - UIImagePickerController 不遵守 iPad 上的视频最长持续时间

objective-c - 属性字符串中的上标美分

ios - numberOfItemsInSection的逻辑问题:

ios - ios App中全局模型的使用

c - 如何释放 C 结构?

ios - 带有异步 UIImageView 的自动布局 UITableViewCell 不工作

ios - 如何将所选行的值显示到下一个 View Controller ?