Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Navigation bar stop being translucent when self.edgesForExtendedLayout = UIRectEdgeNone

- (void)viewDidLoad
{
    [super viewDidLoad];
    if ([self respondsToSelector:@selector(edgesForExtendedLayout)])
    {
        self.edgesForExtendedLayout = UIRectEdgeNone;
        self.navigationController.navigationBar.translucent=YES;
    }

    // Do any additional setup after loading the view.
}

I do not want my scrollView to be behind the navigationBar by default. So I set self.edgesForExtendedLayout = UIRectEdgeNone;.

That viewDidLoad is the mother viewDidLoad of all my viewController.

That's fine. But I like the translucent effect.

It seems that the translucent effect is gone when I set self.edgesForExtendedLayout to none.

How do I set that to none and still got that translucent effect.

enter image description here

enter image description here

I think a good solution would be to arrange the inset of the scrollview.

I did that

- (void)viewDidLoad
{
    [super viewDidLoad];
    if ([self respondsToSelector:@selector(edgesForExtendedLayout)])
    {
        //self.edgesForExtendedLayout = UIRectEdgeNone;
        self.navigationController.navigationBar.translucent=YES;
        self.automaticallyAdjustsScrollViewInsets = YES;
    }

    // Do any additional setup after loading the view.
}

And this is what I got:

enter image description here

like image 319
user4951 Avatar asked Oct 08 '13 05:10

user4951


2 Answers

I have the same issue right now. So if you need to keep translucent navigation bar you should change not edges but insets. Here is the code, that helps me.

if(floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1) {
      CGRect statusBarViewRect = [[UIApplication sharedApplication] statusBarFrame];
      float heightPadding = statusBarViewRect.size.height+self.navigationController.navigationBar.frame.size.height;

      myContentView.contentInset = UIEdgeInsetsMake(heightPadding, 0.0, 0.0, 0.0);
}

Hope this helps.

like image 95
Oleksii Kalentiev Avatar answered Oct 19 '22 17:10

Oleksii Kalentiev


Translucent means that the content under the bar can be seen through the translucency. By turning off the extended edges, the translucency is still there, simply you cannot see it because there's not content below.

like image 26
Gabriele Petronella Avatar answered Oct 19 '22 16:10

Gabriele Petronella