我想更改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);
我也尝试添加
[navigationController.view setAutoresizesSubviews:NO];
启动UINavigationController
后,但看起来仍然相同。
我现在唯一能想到的选择就是在假名UINavigationController
内使用UITabBarController
,这会被横幅遮挡,但这对我来说似乎不必要了。
有没有办法在UINavigationController
内更改视图控制器视图的高度?
答案 0 :(得分: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];
现在,您可以将container
视图控制器添加到导航控制器而不是您的导航控制器。
答案 1 :(得分:0)
@ jjv360的Swift 5版本答案:
class first{
int a;
void func(second b){}
};
class second{
int a;
void func(first b){}
};