UIViewController是否在viewWillAppear和viewDidAppear之间调整大小? [英] UIViewController resizing itself between viewWillAppear and viewDidAppear?

查看:140
本文介绍了UIViewController是否在viewWillAppear和viewDidAppear之间调整大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目中有一个非常奇怪的错误.我的主要视角是UIScrollView.在它里面,我有一个UIViewController(不是UITableViewController),它具有一个UITableView实例变量,以及一些其他UIButtons.我已经将视图控制器的视图框架设置为CGRectMake(0, 64, 320, 388),因为它上方有一个标签栏(尚不可用).起初它很好用,看起来很好,但是一旦我出现并关闭了modalViewController(我相信要重新加载UIViewController),它将UIViewController的视图推到屏幕顶部(默认设置)它设置为CGRectMake(0, 0, 320, 460),但是由于我已经将wantsFullScreenLayout设置为NO,所以现在将其设置为CGRectMake(0, 0, 320, 388).

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).

我已将此问题跟踪到viewWillAppearviewDidAppear之间.这是我取消modalViewController后的确切日志:

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校园[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)

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)

如您所见,在viewWillAppear中,该框架很好,但在viewDidAppear中,它不是.

As you can see, the frame is fine in viewWillAppear, but not in viewDidAppear.

我已经做了以下尝试来修复它:
-在loadViewviewDidLoadviewWillAppearviewDidAppear中设置所需的帧.
-将我的wantsFullScreenLayout设置为NO.
-在方法覆盖中杀死了我的[super viewWillAppear:][super 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.

我该怎么办?!?!?

推荐答案

我的问题是,从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 as addChildViewController:. Using the container view controller algorithm solved my problem. Visit the UIViewController Class Reference for more info.

对于那些懒得在类参考中搜索容器视图控制器"的人,这是该类参考中相关部分的要点:

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:

自定义UIViewController子类也可以充当容器视图 控制器.容器视图控制器管理 它拥有的其他视图控制器的内容,也称为其子级 查看控制器.孩子的观点可以按原样显示,也可以显示在 与容器视图控制器拥有的视图结合.

A custom UIViewController subclass can also act as a container view controller. A container view controller manages the presentation of content of other view controllers it owns, also known as its child view controllers. A child’s view can be presented as-is or in conjunction with views owned by the container view controller.

您的容器视图控制器子类应声明一个公共 关联其子项的界面.这些方法的本质在于 取决于您所创建的容器的语义. 您需要确定您的视图可以显示多少个孩子 控制器,显示这些子项的时间以及它们的位置 出现在您的视图控制器的视图层次结构中.您的视图控制器 类定义子级之间共享的关系(如果有). 通过为您的容器建立一个干净的公共接口,您可以 确保孩子逻辑地使用其功能,而无需访问 有关您的容器如何实现 行为.

Your container view controller subclass should declare a public interface to associate its children. The nature of these methods is up to you and depends on the semantics of the container you are creating. You need to decide how many children can be displayed by your view controller at once, when those children are displayed, and where they appear in your view controller’s view hierarchy. Your view controller class defines what relationships, if any, are shared by the children. By establishing a clean public interface for your container, you ensure that children use its capabilities logically, without accessing too many private details about how your container implements the behavior.

您的容器视图控制器必须关联一个子视图控制器 在将子级的根视图添加到视图层次结构之前,先将其与自身关联. 这样,iOS可以将事件正确地路由到子视图控制器,并 这些控制器管理的视图.同样,删除后 子视图的根视图与其层次结构 子视图控制器本身.制造或破坏这些 关联,您的容器会调用由 基类.这些方法不希望由以下对象的客户调用 您的容器类;它们只能由您的容器的 实现以提供预期的遏制行为.

Your container view controller must associate a child view controller with itself before adding the child’s root view to the view hierarchy. This allows iOS to properly route events to child view controllers and the views those controllers manage. Likewise, after it removes a child’s root view from its view hierarchy, it should disconnect that child view controller from itself. To make or break these associations, your container calls specific methods defined by the base class. These methods are not intended to be called by clients of your container class; they are to be used only by your container’s implementation to provide the expected containment behavior.

这篇关于UIViewController是否在viewWillAppear和viewDidAppear之间调整大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆