如何在iOS中使用“容器视图”?

时间:2021-03-17 16:48:05

I have noticed the UI Component in XCode: Container View.

我已经注意到XCode中的UI组件:容器视图。

如何在iOS中使用“容器视图”?

Based on the description provided I would like to make use of it to display a reusable component of my app in several different screens. I have been looking around online to try and find a basic tutorial or some documentation on it, however I havent found anything of use.

根据所提供的描述,我想利用它在几个不同的屏幕上显示我的应用程序的可重用组件。我一直在网上寻找一个基本的教程或者一些文件,但是我没有找到任何有用的东西。

Please could someone advise on how to wire this up and make use of it? At the moment it also appears that the container view doesn't seem to resize which is problematic. Any tips on how to enable this would be appreciated too.

请给我一些建议,告诉我们如何将这些材料连接起来并加以利用。此时,容器视图似乎没有调整大小,这是有问题的。任何关于如何实现这一点的建议也将得到赞赏。

Cheers.

欢呼。

1 个解决方案

#1


63  

Well let's break this into some simple steps:

让我们把它分成几个简单的步骤:

  1. Drag a container view to the main view of one of your controllers. When you drag the container view, IB will create an embed segue for you and you can resize the container's view by dragging the resize control points as usual. Any changes in the size will be automatically reflected to the view that the segue is pointing to. The idea is that this view will be managed by a different controller, the embedded one. 如何在iOS中使用“容器视图”?

    将容器视图拖到其中一个控制器的主视图。当您拖动容器视图时,IB将为您创建一个embed segue,您可以像往常一样拖动resize控制点来调整容器的视图。大小的任何更改都会自动反映到segue指向的视图中。这个视图将由一个不同的控制器(嵌入的控制器)来管理。

  2. Set your custom subclass as the class of the embedded controller. 如何在iOS中使用“容器视图”?

    将自定义子类设置为嵌入式控制器的类。

  3. Now you're good to go. Note that any containers you add will be available through the childViewControllers property on your main controller. 如何在iOS中使用“容器视图”?

    现在你可以走了。注意,您添加的任何容器都将通过主控制器的childViewControllers属性提供。

This is obviously an oversimplified workflow but it's enough to get you started. For more information on the subject, see Apple's documentation here.

这显然是一个过于简化的工作流,但它足以让您开始工作。有关这个主题的更多信息,请参见这里的苹果文档。

#1


63  

Well let's break this into some simple steps:

让我们把它分成几个简单的步骤:

  1. Drag a container view to the main view of one of your controllers. When you drag the container view, IB will create an embed segue for you and you can resize the container's view by dragging the resize control points as usual. Any changes in the size will be automatically reflected to the view that the segue is pointing to. The idea is that this view will be managed by a different controller, the embedded one. 如何在iOS中使用“容器视图”?

    将容器视图拖到其中一个控制器的主视图。当您拖动容器视图时,IB将为您创建一个embed segue,您可以像往常一样拖动resize控制点来调整容器的视图。大小的任何更改都会自动反映到segue指向的视图中。这个视图将由一个不同的控制器(嵌入的控制器)来管理。

  2. Set your custom subclass as the class of the embedded controller. 如何在iOS中使用“容器视图”?

    将自定义子类设置为嵌入式控制器的类。

  3. Now you're good to go. Note that any containers you add will be available through the childViewControllers property on your main controller. 如何在iOS中使用“容器视图”?

    现在你可以走了。注意,您添加的任何容器都将通过主控制器的childViewControllers属性提供。

This is obviously an oversimplified workflow but it's enough to get you started. For more information on the subject, see Apple's documentation here.

这显然是一个过于简化的工作流,但它足以让您开始工作。有关这个主题的更多信息,请参见这里的苹果文档。