简体   繁体   中英

self.navigationController.navigationBar.translucent = NO; create an extra gap after navigationBar

Let me explain my situation first. I set the UINavigationBar color in my appDelegate Like:

[[UINavigationBar appearance] setBarTintColor:[UIColor colorWithRed:255.0f/255.0f green:87.0f/255.0f blue:10.0f/255.0f alpha:1]];

Now in my some viewController the translucent of UINavigationBar set as YES .

self.navigationController.navigationBar.translucent = YES;

That's why there is a shade over my UINavigationBar . It wasn't showing the exact color. As a solution, I set translucent from YES to NO . It is showing the exact color now, But I am facing that some of my view completely gone from my interface. Here, let me tell you one thing that, so many of views here, is positioned by programmatically, so I am afraid I can't just move every of my viewController s view 64 px high. Just wondering is there any solution to solve the thing. I try with opaque , but no luck. If any one understand my problem please share the solution if you have. Thanks a lot in advance.

From iOS7 if you use a translucent bar ( in UINavigationController or UITabbarController ) the hosted view controller has as default behavior to extend under them. If you say to set the bar as translucent the color of it it will be a combination of the view under it and bat color. That is normal and the only way is to set translucency to no or apply a background image to navigation bar.
Applying frames manually will lead to unexpected result under auto layout, you must use constraints.

[UPDATE]

To create a background image from a solid color you can use that method, the image is 1px square, but there is no problem because it can be stretched or tiled to cover the entire area:

+ (UIImage *) imageWithColor:(UIColor*) color {
    CGRect rect = CGRectMake(0, 0, 1, 1);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetFillColorWithColor(context, color.CGColor);
    CGContextFillRect(context, rect);
    UIImage *colorImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return colorImage;
}

If you see and extra gap is probably because you have also set automaticallyAdjustScrollViewInset to YES, try setting it NO. This property add and extra inset to your view or your vfirst view subview if it inherits from a UIScrollView

它很晚了,但是我遇到了同样的问题,我通过在情节提要中的Viewcontroller上使UINavigationbar都不显示来解决了该问题,并将视图的大小调整为从0,0开始

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM