如何在iOS中使用“容器视图”? [英] How to use a 'Container View' in iOS?

查看:220
本文介绍了如何在iOS中使用“容器视图”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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





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



请有人建议如何连线这个并利用它?目前,似乎容器视图似乎没有调整大小,这是有问题的。任何有关如何启用此功能的提示也将受到赞赏。



干杯。

解决方案

好吧,我们将其分解为一些简单的步骤:


  1. 将容器视图拖到其中一个的主视图中控制器。拖动容器视图时,IB将为您创建嵌入segue,您可以像往常一样拖动调整大小控制点来调整容器视图的大小。大小的任何更改都将自动反映到segue指向的视图。我们的想法是,这个视图将由一个不同的控制器管理,即嵌入式控制器。


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


  3. <现在你很高兴。请注意,您添加的任何容器都可以通过主控制器上的 childViewControllers 属性获得。


这显然是一个过度简化的工作流程,但它足以让你入门。有关该主题的更多信息,请在此处查看Apple的文档


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

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.

解决方案

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.

  2. Set your custom subclass as the class of the embedded controller.

  3. Now you're good to go. Note that any containers you add will be available through the childViewControllers property on your main controller.

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.

这篇关于如何在iOS中使用“容器视图”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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