How to fade out the status bar while not hiding it

前端 未结 5 1952
無奈伤痛
無奈伤痛 2020-12-13 00:43

iOS Developers will surely knows about the issue about status bar and the famous \"slide/hamburger/drawer\". The issue is well explained here: http://uxmag.com/articles/adap

5条回答
  •  醉话见心
    2020-12-13 01:19

    Your main problem is with MMDrawerController. If you'll digg into it you'll find a lot of methods statusbar related such as setShowsStatusBarBackgroundView setStatusBarViewBackgroundColor and more. Something in their code pushes the view up when the statusbar is hidden.

    Alternatively you can use another drawer controller or use custom code.

    Here's a simple way how to accomplishe this:

    enter image description here

    ViewControllerA:

    -(BOOL)prefersStatusBarHidden
    {
        return _hidden;
    }
    - (void)statusHide
    {
        [UIView animateWithDuration:0.4 animations:^() {[self setNeedsStatusBarAppearanceUpdate];
        }completion:^(BOOL finished){}];
    }
    

    ViewControllerB: (Container in ViewControllerA)

    - (IBAction)move:(UIButton *)sender
    {
        parent = (ViewController*)self.parentViewController;
        parent.hidden = !parent.hidden;
        CGRect frame = parent.blueContainer.frame;
        if(parent.hidden)
        {
            frame.origin.x = 150;
        }
        else
        {
            frame.origin.x = 0;
        }
    
        [UIView animateWithDuration:1 animations:^() {parent.blueContainer.frame = frame;}completion:^(BOOL finished){}];
        [parent statusHide];
    }
    

    For iOS 6 compatieblty use:

    [[UIApplication sharedApplication] setStatusBarHidden:_hidden withAnimation:UIStatusBarAnimationFade];
    

    The table view and other subviews will stay in their location and won't be pushed up.

    Edit:

    Adding a NavigationBar:

    UINavigationController will alter the height of its UINavigationBar to either 44 points or 64 points, depending on a rather strange and undocumented set of constraints. If the UINavigationController detects that the top of its view’s frame is visually contiguous with its UIWindow’s top, then it draws its navigation bar with a height of 64 points. If its view’s top is not contiguous with the UIWindow’s top (even if off by only one point), then it draws its navigation bar in the “traditional” way with a height of 44 points. This logic is performed by UINavigationController even if it is several children down inside the view controller hierarchy of your application. There is no way to prevent this behavior.

    Taken from here

    You could very simply subclass UINavigationController and create your own navbar to avoid this annoyness.

提交回复
热议问题