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

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

问题描述

我注意到 XCode 中的 UI 组件:Container View.

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.

请有人建议如何连接并使用它?目前看来 container view 似乎没有调整大小,这是有问题的.任何有关如何启用此功能的提示也将不胜感激.

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.

干杯.

推荐答案

好吧,让我们将其分解为几个简单的步骤:

Well let's break this into some simple steps:

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

  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.

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

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

现在你可以走了.请注意,您添加的任何容器都可以通过主控制器上的 childViewControllers 属性使用.

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

这显然是一个过于简化的工作流程,但足以让您入门.有关该主题的更多信息,请参阅此处的 Apple 文档.

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天全站免登陆