iOS 7 Uisearchdisplaycontroller Search Bar Overlaps Status Bar While Searching

iOS 7 UISearchDisplayController search bar overlaps status bar while searching

Thank you hodade for leading me on the right track! Your solution worked, except it only moved the search bar's frame, leaving my other subviews in the wrong spot. The only thing I changed was to move all the subviews in my view, as well as animate it.

Thanks!

-(void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller {
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
CGRect statusBarFrame = [[UIApplication sharedApplication] statusBarFrame];
[UIView animateWithDuration:0.25 animations:^{
for (UIView *subview in self.view.subviews)
subview.transform = CGAffineTransformMakeTranslation(0, statusBarFrame.size.height);
}];
}
}

-(void)searchDisplayControllerWillEndSearch:(UISearchDisplayController *)controller {
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
[UIView animateWithDuration:0.25 animations:^{
for (UIView *subview in self.view.subviews)
subview.transform = CGAffineTransformIdentity;
}];
}
}

UISearchBar overlaps status bar in iOS

If the navigationBar is visible do the following in ViewDidLoad :

self.edgesForExtendedLayout = UIRectEdgeNone;

If the navigationBar is hidden do the following in ViewDidLoad :

Adjust all the UIView elements by shifting them 20pt

Search bar overlapping status bar in search controller

From your screenshots it appears you're working on iOS 11, with this version the way the UISearchController search bar is added to UI has changed. On iOS 11 is the navigation item that takes care of displaying search so UIKit has not been updated to correctly handle the search bar presented in the table header view.

On iOS ≤10 you should continue to use

self.tableView.tableHeaderView = _searchController.searchBar;

but switch to

self.navigationItem.searchController = _searchController;
self.navigationItem.hidesSearchBarWhenScrolling = YES;

on iOS 11 and later.

Search bar overlaps with status bar on iOS 11

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

Seems to be an iOS 11 bug, or at least an odd behavior…

NavigationBar coincides with status bar when searchDisplayController is activated iOS 7

fixed by doing: [[[parentFileViewController navigationController] navigationBar] setHidden: YES]; in searchDisplayControllerWillBeginSearch method where parentFileViewController contains the searchBar



Related Topics



Leave a reply



Submit