問題描述
我很困惑為什么以及何時需要使用容器視圖?我們如何通過代碼實例化一個容器視圖?
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 中的容器視圖是什么?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!