ios - 设置添加为 subview Controller 的导航 Controller 的框架

标签 ios uinavigationcontroller childviewcontroller

我正在尝试添加一个 UINavigationController 作为 subview Controller ,然后给它一个比其父级更小的框架。但是,更改导航 Controller 的框架不会正确更改导航 Controller 的 Root View Controller 的框架。

viewDidLoad

RootController *rootController = [[RootController alloc] init];
_navController = [[UINavigationController alloc] initWithRootViewController:rootController];
[rootController release];

[self addChildViewController:_navController];
[self.view addSubview:_navController.view];
[_navController didMoveToParentViewController:self];

然后,在 viewWillAppear: 中:

CGRect bounds = self.view.bounds;
bounds.origin.x = 20;
bounds.origin.y = 20;
bounds.size.width = bounds.size.width - 20;
bounds.size.height = bounds.size.height - 20;
_navController.view.bounds = bounds;

虽然导航栏放置正确,但 Root View Controller 的白色背景却不是。我究竟做错了什么?谢谢你的帮助。 enter image description here

最佳答案

如果您在将 subview Controller 添加到父 View Controller 后立即在 viewDidLoad 中执行此操作,它实际上会起作用:

_navController.view.frame = CGRectInset(self.view.bounds, 20, 20);

关于ios - 设置添加为 subview Controller 的导航 Controller 的框架,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13544375/

相关文章:

ios - 在 iOS 的 swift 中以编程方式设置图像的拉伸(stretch)参数

ios - 如何使用 CAGradientLayer 绘制渐变色轮?

ios导航栏右键项目在推送新 View Controller 时移动

ios - 如何更改详细 View Controller 中的后退按钮颜色?

ios - 如何更新 NSFetchedResultsController?

iphone - ViewController 类型名称在一个类中无法识别,但在另一个类中却可以识别?

ios - UINavigationController pop 重置 Root View Controller 的框架

ios - 子 ViewControllers 数组在具有各种容器的 View Controller 中是否具有特定顺序?

ios - UINavigationController 作为 MSMessagesAppViewController 的 subview

ios - 如何向 subview 显示动画,因为它出现在 UIViewController 中