UISearchBar overrides status bar in iOS

I (like everyone else here) find myself in the same problem of overlapping the status bar as everyone else, with a slight twist, and that is why I am opening a new question about this.

There seems to be some mechanism that allows the UISearchBar to know where its position is, which is completely due to the impact.

The jaredsinclair answer here (the default iOS 7-style iOS 7 status bar in the iPhone app ) explains in detail how Apple Engineers allow us to enter logic into our app to blend in as much as possible with the user environment.

I went through a process of thoroughly studying each UIViewController in my application and made the slightest modification possible.

In most cases, I was able to solve the problem using the code I found through several SO answers

// Do any additional setup after loading the view. if ([self respondsToSelector:@selector(edgesForExtendedLayout)]){ self.edgesForExtendedLayout = UIRectEdgeNone; } 

However, this will not work no matter what I do in the specific view where the UINavigationBar is hiding.

UISearchBar on top of status bar

Based on the solution found through SO, I was able to solve this problem by adding the following piece of logic to this particular UIViewController

 if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) { CGRect statusBarFrame = [[UIApplication sharedApplication] statusBarFrame]; viewFrame.origin.y = viewFrame.origin.y+statusBarFrame.size.height; } 

This pushes the UIViewController n pixels down "depending" on the height of the status bar.

The effect of this is shown here.

Hacked position UISearchBar

The problem is that when I enter the search box, UISearchBar adds a 20px add-on at the top, which compensates for the entire user interface.

enter image description here

This leads me to the conclusion that UISearchBar is trying to configure itself, and coincidentally it is configured to the same amount as the height of the status bar.

If I do not hack a position as soon as I enter the search field, then this automatic configuration aligns the UISearchBar neatly under the status bar.

I hope I talked in detail about my confusion, I wonder if anyone has any ideas for a solution.

+17
ios7 overlap uistatusbar uisearchbar
Sep 24 '13 at 7:54 on
source share
6 answers

If the visibility of the NavigationBar is visible in ViewDidLoad, follow these steps:

 self.edgesForExtendedLayout = UIRectEdgeNone; 

If the navigation bar is hidden, follow these steps in ViewDidLoad:

Adjust all UIView elements by moving them to 20pt

+27
Oct 04 '13 at 9:33
source share

Struggling with this problem too. You need to put this in your ViewDontLoad ViewControllers method.

 if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1) { self.edgesForExtendedLayout = UIRectEdgeNone; } 

That should fix it. This is stated in the iOS 7 Migration Guide. Https://developer.apple.com/library/ios/documentation/userexperience/conceptual/TransitionGuide/AppearanceCustomization.html#//apple_ref/doc/uid/TP40013174-CH15-SW1

+4
Sep 24 '13 at 12:39 on
source share

UISearchBar has a delegation method for what you want. Just put 20px on top.

 - (UIBarPosition)positionForBar:(id <UIBarPositioning>)bar { return UIBarPositionTopAttached; } 

Unfortunately, it does not work with UISearchDisplayController.

+4
Sep 27 '13 at 10:39 on
source share

I had the same problem based on suggestions like @Ben here too . I ended up adding the following code that helped me:

 - (void) viewDidLayoutSubviews { if(floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1) { CGRect viewBounds = self.view.bounds; CGFloat topBarOffset = self.topLayoutGuide.length; viewBounds.origin.y = topBarOffset * -1; self.view.bounds = viewBounds; self.edgesForExtendedLayout = UIRectEdgeNone; } } 

alternatively this code also works

 if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) { self.automaticallyAdjustsScrollViewInsets=YES; self.edgesForExtendedLayout = UIRectEdgeNone; self.navigationController.view.backgroundColor = [UIColor whiteColor]; self.navigationController.navigationBar.translucent = YES; } 
+2
Jan 23 '14 at 1:07
source share

If someone wants to solve this problem using AutoLayout, instead of adding a searchBar.top = self.view.top restriction, add a restriction to topLayoutGuide, for example:

 searchBar.top = topLayoutGuide.bottom 
+2
May 25 '15 at 7:41
source share

I don’t quite understand that the search bar adjusts its own height - my search lines do not do this? But.

You can add a restriction to the Top Layout Guide in IB for the search bar. This will cause it to stick to the bottom of the status bar in both ios 6 and ios 7. If you then delete the code in which you manually adjust the height of the status bar. That should take care of this. You can see an example of how to do this: https://developer.apple.com/library/ios/qa/qa1797/_index.html

0
Sep 25 '13 at 14:56
source share



All Articles