Hide status bar in iOS without deleting its view

I want to hide the status bar in the iPhone application when a button is pressed, and I want to show it again when another button is pressed.

I tried to hide the status bar by overriding -(BOOL)prefersStatusBarHiddenin my view controller, but this also removes its top view.

So, when you delete this status bar, a jump occurs. What I want to do is just hide the contents in the status bar while keeping the background status of the status bar.
For example: you can test the same functionality in the gmail application. When you open the side box in the gmail application, then only the contents of the status bar are hidden and there is no transition.

+4
source share
3 answers
  • You need to make a full view screen that appears in the status bar. Store an extra 20 pixels on top of the view to make room for the status bar.
  • Use autoLayout. but do not refer to the Top Layout Guide or the Bottom Layout Guide. Use SuperView Top / Bottom instead
  • Add these lines of code to your viewDidLoad method in your controller or in the container controller if you are using it.

    self.edgesForExtendedLayout = UIRectEdgeAll; self.extendedLayoutIncludesOpaqueBars = YES; self.automaticallyAdjustsScrollViewInsets = NO;

The first line self.edgesForExtendedLayout = UIRectEdgeAll;includes all the edges for the layout. Second, self.extendedLayoutIncludesOpaqueBars = YES;includes opaque stripes also in the layout. If your status bar is not translucent, this line covers the case. The third line self.automaticallyAdjustsScrollViewInsets = NO;indicates that you do not need to insert a view scroll insert.

0
source

bool / 'prefersStatusBarHidden':

- (BOOL)prefersStatusBarHidden {
    return self.yourBool;
}

statusBar, bool :

self.yourBool = NO;
[self setNeedsStatusBarAppearanceUpdate];
-1
    if ([self respondsToSelector:@selector(setNeedsStatusBarAppearanceUpdate)]){
        [self prefersStatusBarHidden];
        [self performSelector:@selector(setNeedsStatusBarAppearanceUpdate)];
    }
    else{
        [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
    }
-1
source

All Articles