3

I have a custom Side Menu class based on UIViewController. Presenting of Side menu looks like:

extension UIViewController: MenuPresentableProtocol {

    func setupMenu() {
        guard let menu = AppDelegate.shared.menu else { return }
        menu.view.frame = view.bounds
        view.addSubview(menu.view)
        menu.view.frame.origin.x = -UIScreen.main.bounds.width
    }

}

This means that the appearance of the status bar depends on the current ViewControllers prefersStatusBarHidden property, which in this case is false.

But I need to hide part of the status bar under the side menu. Is there a way for implement this?

This what I have:

When menu hidden, it looks good.

enter image description here

But when menu presents, ...

enter image description here

P.S. I tried to use this answer, but it didn't help me.

Sergey Hleb
  • 152
  • 1
  • 16
  • I think it would look better to either 1) draw the menu _below_ the status bar, or 2) hide the status bar when the menu is open. #1 is better, if only because #2 would cause the screen to jump up and down 20 pixels whenever the menu appeared and disappeared. – NRitH Dec 17 '18 at 19:38
  • @NRitH, #2 - bad implementation, I agree. I don't want to do this. #1 - haven't got a difference with my implementation, but status bar is visible, and it's confused a customer. – Sergey Hleb Dec 17 '18 at 19:44
  • It's not recommended to hide the status bar (or part of it) if you aren't providing the full screen experience (i.e. viewing full screen media like photos/videos) to the user. You might want to have a look at the [Status Bar HIG](https://developer.apple.com/design/human-interface-guidelines/ios/bars/status-bars/) from Apple. – nayem Dec 20 '18 at 10:40
  • I know, but I need it. – Sergey Hleb Dec 21 '18 at 06:10

3 Answers3

3

Either you can hide the status bar fully OR you can show full. There is no way to hide part of status bar.

You can use the same background color as statusbar's textcolor in side menu and some opposite color on view controller. In this case, statusbar's text color will have same color as your sidemenu's background color, it means that text will not be visible. So, it will give effect that your half statusbar is hidden and half not.

You will not find any single app on appstore with such case that you want, as it is not possible at all. If some app is looking to have same effect, then check its sidemenu's background color and statusbar's text color. That both will be same.

Mehul Thakkar
  • 12,440
  • 10
  • 52
  • 81
1

Answers are right, you cannot hide just a part of the status bar. However you can give an almost-perfect illusion you do it by rebuilding your own statusbar clone and display it as you wish: iOS gives you the infos you need:

  • the time,
  • your carrier name,
  • the battery level
  • and battery charging state...
  • You will just miss the real cellular signal strength info, but you will then need to draw momentarily a fake one just for the time to present you menu and do your animation...

At the end this is more an art work than hard coding :)

JBA
  • 2,889
  • 1
  • 21
  • 38
0

This code snippet will actually hide your status bar with a view

        UIView *view = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.width, 20)] autorelease];
        view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"PortraitNavigationBG"]]; 
        //or use same color as your background

        [self.navigationController.view addSubview:view];
Habib Ali
  • 272
  • 2
  • 13