我很困惑为什么以及何时需要使用容器视图?我们如何通过代码实例化一个容器视图?
I'm confused that why and when we need to use the container view? and how can we instantiate a Container View by code?
容器视图是一种视图,您可以将其拖入您的情节提要中已有的视图控制器中(我们称之为 viewControllerA).你会自动获得一个通过嵌入转场连接到该视图的视图控制器.这个新的视图控制器有它的框架集,所以它与容器视图的大小相同——如果你调整容器视图的大小,控制器也会自动调整大小.因此,如果您愿意,可以将多个容器视图拖入 viewControllerA 中,每个视图控制器都有自己的视图控制器.在代码中,如果您需要访问这些嵌入式视图控制器,可以从 viewControllerA.childViewControllers 访问它们——这将为您提供您拥有的任何嵌入式视图控制器的数组.
The container view is a view that you can drag into one of your view controllers that you already have in your storyboard (we'll call this viewControllerA). You automatically get a view controller connected to this view via an embed segue. This new view controller has its frame set, so that it's the same size as the container view -- if you resize the container view, the controller will automatically resize as well. So, if you want, you can drag in multiple container views into viewControllerA, and each will have its own view controller. In code, if you need to access these embedded view controllers, they can be accessed from viewControllerA.childViewControllers -- that will give you an array of any embedded view controllers that you have.
在 WWDC 2012 Session Videos 视频中讨论了这些容器视图,名为在您的应用中采用 Storyboards".
There is a discussion of these container views in the WWDC 2012 Session Videos video called "Adopting Storyboards in Your App".
这篇关于iOS 5 SDK 中的容器视图是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!