我可以通过编程方式创建UIContainerView吗? [英] Can I create a UIContainerView programmatically?

查看:66
本文介绍了我可以通过编程方式创建UIContainerView吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个使用UIContainerView托管UIViewController的动态视图流.需要将UIContainerView(或UIViewController s)以编程方式添加到UIView中,以允许多个并排.

我一直在寻找,但是找不到任何可用于创建我的UIContainerView的构造函数.

是否有一种简单的方法来执行此操作,或者是否违反了创建可重用视图的常规准则?

总而言之,我想实现以下目标:

 var containerView = UIContainerView()
containerView.add(myViewController)
 

解决方案

UIContainerView只是一种将viewController添加为另一个子视图并设置其边界的视觉方法.

您可以通过编程方式执行此操作,方法是将第二个viewController添加为第一个viewController的子级,获取第二个viewController的视图并将其放置在第一个viewController的某个位置.

像这样的东西

childVC = [[SomeViewController alloc] init];

[self addChildViewController:childVC];

[self.view addSubview:childVC.view];

[childVC didMoveToParentViewController:self];

I'm trying to create a dynamic view flow that uses UIContainerViews to host UIViewControllers. The UIContainerViews (or UIViewControllers) need to be programmatically added to the UIView to allow multiple side by side.

I've been looking around, but can't find any constructors I can use to create my UIContainerView.

Is there a simple way to do this or is it against normal guidelines for creating reusable views?

To sum up, I want to achieve something like this:

var containerView = UIContainerView()
containerView.add(myViewController)

解决方案

A UIContainerView is just a visual way to add a viewController as a child of another and setting its bounds.

You can do this programatically by adding the second viewController as a child of the first, taking the second's view and placing it somewhere on the first's view.

Something like this;

childVC = [[SomeViewController alloc] init];

[self addChildViewController:childVC];

[self.view addSubview:childVC.view];

[childVC didMoveToParentViewController:self];

这篇关于我可以通过编程方式创建UIContainerView吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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