Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setNavigationBar translucent pushes view down

I have a view with a transparent UINavigationBar and a UITableView about 10px below it. There's a UIImageView with a cool polygon image in the background that I'm animating in a parallax-y way for view transitions.

Here's the code for the transparent nav bar:

self.navigationController.navigationBar.shadowImage = [UIImage new];
self.navigationController.navigationBar.translucent = YES;
[self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];

I'm not using storyboards at all for this project

I also have a floating action button down in the bottom right. The nav bar title UILabel I've added to the titleView is swapped for a UITextField for search functionality on tap of a right nav button. When this happens, I'm setting

self.navigationController.navigationBar.translucent = YES;

This all works well, except that by setting translucent = NO the view pushes the all of the content down by the height of the nav bar.

enter image description here Search Mode

I can hack together some frame changes to compensate for this, but I was wondering if there was a more standard practice solution for this.

like image 975
d2burke Avatar asked Dec 15 '22 10:12

d2burke


1 Answers

The property you want to set is extendedLayoutIncludesOpaqueBars, if this property is set to YES then your view will layout the same as if the navigation bar were translucent.

You mentioned that you're not using storyboards, but for others who do this can be set in the Attributes Inspector for the view controller under the 'Extend Edges' section by ticking the checkbox titled 'Under Opaque Bars'.

like image 88
geraldWilliam Avatar answered Feb 06 '23 14:02

geraldWilliam