Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/109.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UINavigationController donesn';我不能正常工作_Ios_Objective C - Fatal编程技术网

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];