gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 04:26:40 25 4
gpt4 key购买 nike

我正在尝试添加一个 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com