更改UINavigationController内的视图高度

Ale*_*lex 6 iphone uiviewcontroller uinavigationcontroller ios

我想更改a UIViewController's内部视图的高度,UINavigationController以在底部显示横幅,这样就不会遮挡任何内容.

我认为只需更改视图的框架就可以轻松实现,viewDidLoad但这样做不起作用:

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

我也尝试添加

[navigationController.view setAutoresizesSubviews:NO];
Run Code Online (Sandbox Code Playgroud)

在启动后UINavigationController它仍然看起来一样.

我现在能想到的唯一选择就是在UINavigationController里面使用一个UITabBarController被横幅遮挡的假人,但这似乎对我来说不必要的复杂.

有没有办法改变视图控制器的视图高度UINavigationController

jjv*_*360 5

无法从视图控制器中更改视图控制器的视图,但您可以使用自定义容器视图控制器:

// 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];
Run Code Online (Sandbox Code Playgroud)

现在,您可以将container视图控制器添加到导航控制器而不是您的导航控制器.