我在navigationItem中自定义添加UISearchBar控制器。它在iphone上工作正常,但在ipad上给出了问题。
我在导航栏下使用容器视图,我在其中调用不同的视图控制器。但是一旦我选择了搜索栏,搜索栏就会上升以隐藏状态栏,但导航下的容器视图并没有向上移动。
self.searchController = UISearchController(searchResultsController: nil)
self.searchController.searchBar.delegate = self;
self.searchController.searchBar.placeholder = "Search"
if let textfield = self.searchController.searchBar.value(forKey: "searchField") as? UITextField {
if let backgroundview = textfield.subviews.first {
backgroundview.backgroundColor = UIColor.white
backgroundview.layer.cornerRadius = 10;
backgroundview.clipsToBounds = true;
}
}
self.searchController.searchBar.tintColor = UIColor.cityworksBlue()
if #available(iOS 11.0, *) {
self.searchController.searchBar.showsScopeBar = false;
self.searchController.dimsBackgroundDuringPresentation = false
self.searchController.hidesNavigationBarDuringPresentation = true
navigationItem.searchController = self.searchController
navigationItem.hidesSearchBarWhenScrolling = false
}
我想要做的是,如果搜索栏向上移动,那么容器视图也应该向上移动。它适用于iphone但在ipad中出现问题。