The navigation bar stops 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 default navigation bar. So I set self.edgesForExtendedLayout = UIRectEdgeNone ;.

This viewDidLoad is the mother viewDidLoad of my entire viewController.

It's good. But I like the translucent effect.

It seems that the translucent effect disappears when I set self.edgesForExtendedLayout to equal.

How to set the value to "none" and get the effect of translucency.

enter image description here

enter image description here

I think a good solution would be to organize a scroll attachment.

I did it

 - (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 here is what I got:

enter image description here

+6
source share
2 answers

Transparent means that the content under the panel can be seen through transparency. By turning off the extended edges, transparency still exists, you just don’t see it because there is no content below.

+2
source

I have the same problem right now. Therefore, if you need to save a translucent navigation bar, you should change the edges, not the edges. 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.

+6
source

Source: https://habr.com/ru/post/955468/


All Articles