UIViewController 在 viewWillAppear 和 viewDidAppear 之间调整自身大小?
我的项目中有一个非常奇怪的错误。我有一个 UIScrollView
作为我的主要大视图。在它的内部,我有一个 UIViewController
(不是 UITableViewController
),它有一个 UITableView
实例变量,以及一些杂项 UIButtons< /代码>。我已将视图控制器的视图框架设置为 CGRectMake(0, 64, 320, 388)
,因为它上面有一个选项卡栏(这还不起作用)。起初,它工作得很好,看起来也很棒,但是一旦我呈现并关闭了 modalViewController
(我相信,因此重新加载了 UIViewController
),它就会推送 UIViewController
code> 的视图到屏幕顶部(默认设置为 CGRectMake(0, 0, 320, 460) ,但由于我设置了 wantsFullScreenLayout
为 NO
,现在将其设置为 CGRectMake(0, 0, 320, 388)
,
我已将此问题跟踪到 viewWillAppear
之间的某个位置。和 viewDidAppear ,这是我关闭 modalViewController 后的确切日志:
2011-05-06 11:08:39.974 Campus[1570:207] 框架为 0.000000、64.000000、320.000000、388.000000 (viewWillAppear)
2011-05-06 11:08:40.378 Campus[1570:207] 框架为 0.000000、0.000000、320.000000、388.000000 (viewDidAppear)
如您所见,框架在 viewWillAppear
中很好,但在viewDidAppear
。
我已执行以下操作来尝试修复该问题:
- 在 loadView
、viewDidLoad
、viewWillAppear
和 viewDidAppear
中设置所需的框架。
- 将我的 wantsFullScreenLayout
设置为 NO
。
- 杀死了我的方法覆盖中的 [super viewWillAppear:]
和 [super viewDidAppear:]
调用。
我应该怎么办?!?!?
I've got a really strange bug in my project. I've got a UIScrollView
as my main, big view. Inside of it, I have a UIViewController
(not UITableViewController
) which has a UITableView
instance variable, as well as some miscellaneous UIButtons
. I have set the view controller's view frame to CGRectMake(0, 64, 320, 388)
, as I have a tab bar above it (this is not functional yet). At first it works great and looks great, but once I present and dismiss a modalViewController
(thus reloading the UIViewController
, I believe), it pushes the UIViewController
's view to the top of the screen (by default setting it to CGRectMake(0, 0, 320, 460)
, but since I've set wantsFullScreenLayout
to NO
, it now sets it to CGRectMake(0, 0, 320, 388)
.
I've tracked this problem to somewhere between viewWillAppear
and viewDidAppear
. Here are my exact logs after dismissing the modalViewController
:
2011-05-06 11:08:39.974 Campus[1570:207] Frame is 0.000000, 64.000000, 320.000000, 388.000000 (viewWillAppear)
2011-05-06 11:08:40.378 Campus[1570:207] Frame is 0.000000, 0.000000, 320.000000, 388.000000 (viewDidAppear)
As you can see, the frame is fine in viewWillAppear
, but not in viewDidAppear
.
I've done the following things to try to fix it:
- Set the desired frame in loadView
, viewDidLoad
, viewWillAppear
, and viewDidAppear
.
- Set my wantsFullScreenLayout
to NO
.
- Killed my [super viewWillAppear:]
and [super viewDidAppear:]
calls in my method overrides.
What should I do?!?!?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我的问题是,从 iOS 4 开始,Apple 只支持每个窗口 1 个视图控制器。然而,从 iOS 5 开始,Apple 添加了对容器视图控制器的支持,并向
UIViewController
添加了方法,例如addChildViewController:
。使用容器视图控制器算法解决了我的问题。请访问 UIViewController 类参考更多信息。编辑:对于那些懒得在类参考中搜索“容器视图控制器”的人,这里是类参考中相关部分的要点:
My problem here was that, as of iOS 4, Apple only supported 1 view controller per window. However, as of iOS 5, Apple has added support for container view controllers, and has added methods to
UIViewController
such asaddChildViewController:
. Using the container view controller algorithm solved my problem. Visit the UIViewController Class Reference for more info.EDIT: for those of you too lazy to search "container view controller" in the class reference, here's the gist of the related section in the class reference: