ios – UISearchController不重新显示旋转导航栏

我已经实施了UISearchController,除了…

当我点击搜索栏时,导航栏将按照预期的方式消失.当我将手机旋转到横向视图时,我得到这个观点是有道理的.

但是,当我将手机旋转回到纵向视图(仍在搜索类型区域中选择)时,我得到以下视图.

您可以看到导航栏从不重新出现.我觉得我正在实施一个基本的搜索控制器.可能是什么原因造成的?

self.venueSearchController = [[UISearchController alloc] initWithSearchResultsController:nil];
self.venueSearchController.searchResultsUpdater = self;
self.venueSearchController.searchBar.delegate = self;
self.venueSearchController.dimsBackgroundDuringPresentation = NO;
self.venueSearchController.hidesNavigationBarDuringPresentation = YES;
self.venueSearchController.searchBar.frame = CGRectMake(self.venueSearchController.searchBar.frame.origin.x,self.venueSearchController.searchBar.frame.origin.y,self.venueSearchController.searchBar.frame.size.width,44.0);

self.definesPresentationContext = YES;

self.navigationController.navigationBar.translucent = YES;
self.venueSearchController.searchBar.translucent = YES;

self.tableView.tableHeaderView = self.venueSearchController.searchBar;

解决方法

看起来UISearchController忘记在状态栏重新出现时重新设置searchBar的框架.我认为这可能是UISearchController中的一个错误;似乎有一些列在 radar.似乎searchBar的超级视图(这是内部的UISearchController)最终以错误的高度.这是令人烦恼的,因为解决方案因此涉及到SearchController的视图层次结构,哪个苹果可以改变…你可能想添加一个iOS版本的检查,所以它只运行指定的版本.

如果将下面的代码添加到视图控制器,则在trait集合更改时将调用代码.它检查a)搜索控制器是否处于活动状态,b)statusBar不被隐藏,并且c)searchBar origin-y为0,如果是,则将superview的高度增加到statusBar的高度,searchBar下来.

override func traitCollectionDidChange(prevIoUsTraitCollection: uitraitcollection?) {
    let app = UIApplication.sharedApplication()
    if searchController!.active && !app.statusBarHidden && searchController?.searchBar.frame.origin.y == 0 {
        if let container = self.searchController?.searchBar.superview {
            container.frame = CGRectMake(container.frame.origin.x,container.frame.origin.y,container.frame.size.width,container.frame.size.height + app.statusBarFrame.height)
        }
    }
}

目标C

- (void) traitCollectionDidChange: (uitraitcollection *) prevIoUsTraitCollection {

    [super traitCollectionDidChange: prevIoUsTraitCollection];

    if(self.venueSearchController.active && ![UIApplication sharedApplication].statusBarHidden && self.venueSearchController.searchBar.frame.origin.y == 0)
    {
        UIView *container = self.venueSearchController.searchBar.superview;

        container.frame = CGRectMake(container.frame.origin.x,container.frame.size.height + [UIApplication sharedApplication].statusBarFrame.size.height);
    }
}

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...