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

2024-04-04

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

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

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

Cheers.


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

  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. enter image description here

  2. Set your custom subclass as the class of the embedded controller. enter image description here

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

这显然是一个过于简化的工作流程,但足以让您入门。有关该主题的更多信息,请参阅此处的 Apple 文档 https://developer.apple.com/library/prerelease/ios/featuredarticles/ViewControllerPGforiPhoneOS/ImplementingaContainerViewController.html.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何在 iOS 中使用“容器视图”? 的相关文章

随机推荐