Navigation Controller Transparent Bar Style is not working

前端 未结 12 637
情书的邮戳
情书的邮戳 2020-12-31 13:57

I am using a navigation controller, and I have the style set to :

navController.navigationBar.barStyle = UIBarStyleBlackTranslucent;

But wh

相关标签:
12条回答
  • 2020-12-31 14:23

    I ran into this same problem (in 3.1.3) and while you can't set the bar style after the navigationBar has already been setup you CAN set the tintColor and translucent values whenever you like:

        self.navigationController.navigationBar.tintColor = [UIColor blackColor];
        self.navigationController.navigationBar.translucent = YES;
    

    Will create the 'blackTranslucent' bar, I change the navigationBar look when I push certain view controllers onto the stack.

    0 讨论(0)
  • 2020-12-31 14:25

    If you set your nav controller's navigationBar to transparent in your App delegate early enough (It worked for me before adding the nav controller to the window), it will automatically shift your view up underneath the navigation bar.

    Unfortunately it does not also shift your view underneath the status bar. Sad, it looks like you need to implement your own version of UINavigationController. Luckily, it's not too bad as UINavigationBar is pretty reusable.

    0 讨论(0)
  • 2020-12-31 14:29

    I believe the UINavigationController assumes that your controller view frames don't include the area beneath the navigation bar.

    UIBarStyleBlackTranslucent is more often used for UIToolbar, so Apple probably didn't make it easy to use it nicely with UINavigationBar. You'll probably need to abandon the UINavigationController, or start hacking the frames (careful with rotations), if you want to reliably render under the bar area.

    Also, if your intention is to hide the navigation bar after a few seconds, you'll have a much easier time if you make it fade out (like the Photos app) instead of trying to slide it up (like Mobile Safari). Trust me on that one... that took me a lot of time to learn the hard way.

    0 讨论(0)
  • 2020-12-31 14:30

    The navigation controller offsets the coordinate sytem of all it's subviews so they draw below the navigation bar.

    Extend your view's frame into the negative y domain for it to draw under the navigation bar.

    0 讨论(0)
  • 2020-12-31 14:30

    try to use this, may be it will helpful.

    _topToolBar.barStyle = UIBarStyleBlackTranslucent;
    _topToolBar.alpha = 0.3;
    
    0 讨论(0)
  • 2020-12-31 14:31

    Simply use a transparent background image, and translucent = YES to allow the content to flow below the bar. Works on iOS 5 / 6. Add in viewDidLoad.

    self.navigationController.navigationBar.translucent = YES;
    UIImage * backgroundImage = [UIImage imageNamed:@"spacer.gif"];
    [self.navigationController.navigationBar setBackgroundImage:(UIImage *)backgroundImage forBarMetrics:UIBarMetricsDefault];
    

    I attached the spacer.gif image here, a single 1px x 1px transparent image.

    spacer.gif

    0 讨论(0)
提交回复
热议问题