当使用自定义容器 View Controller 时,我不太明白为什么呈现 View Controller 需要指定 from,因为作为容器类,它应该已经知道 View 层次结构中的内容,不是吗?
transitionFromViewController:toViewController:duration:options:animations:completion:
最佳答案
容器 View Controller 有时需要将所包含 Controller 的 View 放入其自己 View 的特定 subview 中。 (例如,SplitViewController 重新实现可能具有分别保存主 Controller View 和详细 Controller View 的左定位 View 和右定位 View 。)提供 fromViewController 告诉 UIViewController 应在 View 层次结构中的何处插入新 Controller 的 View ,以及应删除哪个特定 View 动画之后。
(与另一个答案相反, View 的帧根本没有为您设置。您可以在调用之前和动画 block 中执行此操作。“Creating Custom Container View Controllers ”文档中的系统指南有一个很好的例子。)
事实上,实际上使用 transitionFromViewController:...
似乎是可选的。您可以手动管理 View 层次结构,无论是否有动画,效果都很好。我仍在形成我的意见,但我认为我更喜欢手动执行,以便更轻松地处理其中一个 VC 为零的情况。
关于iOS 容器 View Controller - 为什么transitionFromViewController需要fromViewController?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9123633/