Change view height inside UINavigationController

I want to change the height of UIViewController's inside the UINavigationController to display the banner below so that it doesn't hide anything.

I thought it would be pretty simple just changing the view frame in viewDidLoad , but that didn't work:

 CGRect frame = self.view.frame; self.view.frame = CGRectMake(frame.origin.x, frame.origin.y, frame.size.width, frame.size.height - 49.0f); 

I also tried adding

 [navigationController.view setAutoresizesSubviews:NO]; 

after starting UINavigationController , but it still looks the same.

The only option I can think of now is to use the UINavigationController inside the dummy UITabBarController , which will be hidden by the banner, but this seems to me unnecessarily complicated.

Is there a way to change the height of the view controller view inside the UINavigationController ?

+4
source share
1 answer

It is not possible to change the view of a view controller from a view controller, but you can use a custom container view controller:

 // Create container UIViewController* container = [[UIViewController alloc] init]; // Create your view controller UIViewController* myVc = [[MyViewController alloc] init]; // Add it as a child view controller [container addChildViewController:myVc]; [container.view addSubview:myVc.view]; myVc.view.autoresizingMask = UIViewAutoresizingMaskFlexibleWidth | UIViewAutoresizingMaskFlexibleHeight; myVc.view.frame = CGRectMake(0, 0, container.view.bounds.size.width, container.view.bounds.size.height-200); // Add your banner UIImageView* imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"banner"]]; imgView.autoresizingMask = UIViewAutoresizingMaskFlexibleWidth| UIViewAutoresizingMaskFlexibleTopMargin; imgView.frame = CGRectMake(0, container.view.bounds.size.height-200, container.view.bounds.size.width, 200); [myVc.view addSubview:imgView]; 

Now you can add the container display controller to your navigation controller, and not to your own.

+4
source

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


All Articles