Ios UINavigationController donesn';我不能正常工作
代码: 我想做的是添加一个Ios UINavigationController donesn';我不能正常工作,ios,objective-c,Ios,Objective C,代码: 我想做的是添加一个UINavigationController(childNaviVC)作为指定VC的子viewcontroller(subVC),并使用UINavigationController的根viewcontroller来显示内容; 我遇到的问题是UINavigationController的根视图(subVC)大小与UINavigationController的父VC一致 红色视图大小不等于青色 谢谢将函数viewdilayoutsubviews添加到childrenvc中
UINavigationController
(childNaviVC)作为指定VC的子viewcontroller(subVC),并使用UINavigationController
的根viewcontroller来显示内容;
我遇到的问题是UINavigationController
的根视图(subVC)大小与UINavigationController
的父VC一致
红色视图大小不等于青色
谢谢将函数
viewdilayoutsubviews
添加到childrenvc中,它成功了。
-(无效)ViewDidLayoutSubView{
UINavigationController * childNaviVC = [[UINavigationController alloc] initWithRootViewController:self.subVC];
[self addChildViewController:childNaviVC];
[self.view addSubview:childNaviVC.view];
[childNaviVC.view setFrame:CGRectMake(0.0f, 0.0f, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)];
self.subVC.view.frame = childNaviVC.view.frame;
[childNaviVC.view addSubview:self.subVC.view];
[childNaviVC didMoveToParentViewController:self];
一个问题是您正在双重添加子视图的视图。子VC的addSubView将打破导航控制器中的自动布局约束 更改您的呼叫以匹配以下内容,并查看您得到的结果:
self.view.frame=CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height);
}
我只想在view中显示childrenVC的navigationbarreset框架WillAspect函数不起作用是导航栏的大小偏移量吗?您能显示您期望的输出类型吗?有任何示例屏幕截图吗?红色视图的底部与青色视图相同。我可以知道您在哪个控制器
VIEWDIDLAYOUTPVIEWS
类中工作吗必须编写此框架设置吗?它是self.subVC
它是真正的工作
UINavigationController * childNaviVC = [[UINavigationController alloc] initWithRootViewController:self.subVC];
[self addChildViewController:childNaviVC];
[self.view addSubview:childNaviVC.view];
[childNaviVC.view setFrame:self.view.bounds];
[childNaviVC didMoveToParentViewController:self];