UIView与容器视图 [英] UIView vs Container View

查看:72
本文介绍了UIView与容器视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这就是我要解决的问题.

So here is the problem I am trying to solve.

在每个viewController中,我都试图插入广告和实际的控制元素.我在raywenderlinch.com上完成了几节教程,以了解人们如何专业地在其应用中放置广告.他们使用UIView在视图控制器的mainview下有两个视图.因此,我完全理解,一个subview持有广告,而另一个subview持有实际的应用程序内容.如果广告已加载,请占用屏幕,否则让其他视图具有所有可用区域.

In each viewController I am trying to insert ads and the actual control elements. I finished couple of tutorial on raywenderlinch.com to understand that how people professionally put ads in their app. They used UIViews to have two views under mainview of view controller. So I completely understood that one subview hold the ads and another is holding actual app contents. if Ad is loaded take up the screen or else let other view have all available area.

回到xcode之后,我开始按照在那学习的方式进行编码.但是当我将UIView放在情节提要上时,我看到了containerView,我认为在编写本教程时该内容不存在. 因此,我在这里询问这两种方法以及它们的优缺点.
因此基本上是UIViewContainerView.我应该怎么做,为什么?
任何帮助将不胜感激.

After I came back to xcode I started coding the way I learned there. but when I was dropping UIView on storyboard, I saw containerView, which I think was not present when the tutorial was written.
So I am here to ask about the both approach and their pros and cons.
So basically its UIView vs ContainerView. Which way I should do, and why ?
Any help would be greatly appreciated.

推荐答案

您已经拥有视图并且不需要专用的视图控制器来构建和处理其中的交互,便可以使用UIView.

You use UIView when you already have a view and you do not need to have a dedicated view controller to build and handle interactions within it.

UIView 帮助页面:

UIView对象声明其包围superview的矩形区域(其在视图层次结构中的父级),并负责该区域中的所有绘图...

UIView object claims a rectangular region of its enclosing superview (its parent in the view hierarchy) and is responsible for all drawing in that region ...

简化的结构: YourViewController ---(有)---> UIView

当需要在现有视图控制器中嵌入另一个视图控制器时,请使用UIContainerView.嵌入式视图控制器负责返回UIViewContainer所占区域的视图.因此,您的UIContainerView知道使用哪个视图控制器在其占用的区域内渲染UIView.

You use UIContainerView when you need to embed another view controller in the one that you already have. The embedded view controller is in charge of returning a view for the region that the UIViewContainer occupies. Therefore, your UIContainerView knows which view controller to use to render UIView inside the region it occupies.

UIContainerView 帮助页面:

容器视图在视图控制器的视图子图中定义一个可以包含子视图控制器的区域.

Container View defines a region within a view controller's view subgraph that can include a child view controller.

简化的结构: YourViewController ---(有)---> SubViewController ---(有)---> UIView

该SubViewController返回一个视图并处理其事件.

That SubViewController returns a view and handles its events.

这篇关于UIView与容器视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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