搜索栏与iOS 11上的状态栏重叠 [英] Search bar overlaps with status bar on iOS 11
问题描述
我正在使用UISearchController和UISearchResultsController来实现搜索功能。
I am using a UISearchController and a UISearchResultsController to implement search functionality.
MySearchResultsController实现了UISearchResultsUpdating和UISearchBarDelegate:
MySearchResultsController implements UISearchResultsUpdating and UISearchBarDelegate:
override open func viewDidLoad() {
super.viewDidLoad()
self.edgesForExtendedLayout = [];
self.automaticallyAdjustsScrollViewInsets = false;
}
我在tableHeader中的MyTableViewController中显示搜索栏,
I display the searchbar in the tableHeader like this in MyTableViewController:
- (void)viewDidLoad {
[super viewDidLoad];
self.searchController = [[UISearchController alloc] initWithSearchResultsController:self.searchResultsController];
self.searchController.searchResultsUpdater = self.searchResultsController;
self.searchController.searchBar.delegate = self.searchResultsController;
self.searchController.searchBar.scopeButtonTitles = @[NSLocalizedString(@"SEARCH_SCOPE_TEMPERATURES", nil), NSLocalizedString(@"SEARCH_SCOPE_KNOWHOW", nil)];
self.tableView.tableHeaderView = self.searchController.searchBar;
self.definesPresentationContext = YES;
}
这在以前非常有效,但是在iOS 11下,搜索栏与状态重叠轻按一下即可看到它(请参见屏幕截图)。我尝试了许多其他方法来使其正确显示,但尚未找到解决方案。
This worked perfectly before, but under iOS 11 the search bar overlaps with the status bar as soon as I tap into it (see screenshots). I tried lots of different things to get it to display correctly but haven't found a solution yet.
推荐答案
我发现问题在于呈现视图控制器也设置了
I found that the problem was that the presenting view Controller also sets
override open func viewDidLoad() {
super.viewDidLoad()
self.edgesForExtendedLayout = [];
self.automaticallyAdjustsScrollViewInsets = false;
}
我必须这样做,因为表视图实际上并没有完全扩展
I have to do this because the table view does not actually extend all the way to the top.
我在演示视图控制器中这样解决了这个问题:
I solved this like that in my presenting view Controller:
override open func viewDidLoad() {
super.viewDidLoad()
self.automaticallyAdjustsScrollViewInsets = false;
if (@available(iOS 11.0, *)) {
//NSLog(@"iOS 11.0");
} else {
self.edgesForExtendedLayout = UIRectEdgeNone;
//NSLog(@"iOS < 11.0");
}
}
似乎是iOS 11错误,或者至少是奇怪的行为……
Seems to be an iOS 11 bug, or at least an odd behavior…
这篇关于搜索栏与iOS 11上的状态栏重叠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!