Ios UINavigationBar中的UISearchController在不扩展边的情况下按弹出视图调整大小

Ios UINavigationBar中的UISearchController在不扩展边的情况下按弹出视图调整大小,ios,iphone,uinavigationcontroller,autolayout,uisearchcontroller,Ios,Iphone,Uinavigationcontroller,Autolayout,Uisearchcontroller,我试图实现一个UISearchController,它的搜索栏位于UINavigationController的导航栏中。此导航栏在Interface Builder中关闭了半透明和所有延伸边 设置非常简单: ViewControllerWithSearchController嵌入到UINavigationController中。我的viewController代码如下所示: class ViewControllerWithSearchController: UIViewController,

我试图实现一个
UISearchController
,它的搜索栏位于
UINavigationController
的导航栏中。此导航栏在Interface Builder中关闭了半透明和所有延伸边

设置非常简单:

ViewControllerWithSearchController
嵌入到
UINavigationController
中。我的viewController代码如下所示:

class ViewControllerWithSearchController: UIViewController, UISearchControllerDelegate, UISearchResultsUpdating, UISearchBarDelegate {

var searchController: UISearchController!

override func viewDidLoad() {
    super.viewDidLoad()

    definesPresentationContext = true
    initializeSearchController()
}

// MARK: - Search

func initializeSearchController() {

    // Create and configure the UISearchController
    searchController = UISearchController(searchResultsController: nil)
    searchController.delegate = self
    searchController.searchResultsUpdater = self
    searchController.dimsBackgroundDuringPresentation = false
    searchController.searchBar.delegate = self
    searchController.searchBar.sizeToFit()
    searchController.hidesNavigationBarDuringPresentation = false
    navigationItem.titleView = searchController.searchBar
}

override func viewDidAppear(animated: Bool) {
    super.viewDidAppear(animated)

    // Check the frame of the view
    print(view.frame)
}

func updateSearchResultsForSearchController(searchController: UISearchController) {
    // Some code here
}
}
当我运行这个时,它工作了。初始运行时ViewController视图的框架是
(0.0、64.0、375.0、603.0)

此viewController包含一个按钮,用于将通用viewController推送到堆栈上。当我弹出此viewController时,
ViewControllerWithSearchController
的框架保持不变(正确的行为)

但是,当我激活搜索栏,然后按下并弹出第二个UIViewController(搜索栏处于活动状态时),
ViewControllerWithSearchController
的帧设置为
(0.0,0.0,375.0,667.0)
即使此行为已关闭,视图仍会扩展到导航栏下方。

所有涉及的ViewController都在InterfaceBuilder中禁用了“延伸边”选项

现在,我已经通过启用所有“扩展边”选项实现了一种变通方法。这会产生一点开销,所以我不想这样做。有没有更好的办法来解决这个问题

我附上了一个示例项目来说明这个问题


我遇到了完全相同的问题,无法找到好的解决方案。我最后做的是检查
viewdilayoutsubviews
中的
edgesForExtendedLayout
的值。如果值为
UIRectEdgeNone
但控制器的
self.view.frame
在状态栏和/或工具栏下延伸,我会在
viewdilayoutsubview
中调整
self.view.frame
。不确定这是否比建议的解决方案好,但这只是另一种选择,似乎效果不错。