我正在尝试添加一个 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 的白色背景却不是。我究竟做错了什么?谢谢你的帮助。
最佳答案
如果您在将 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/