ios - UIView 与容器 View

标签 ios xcode uiview uicontainerview iad

这就是我要解决的问题。

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 放到 Storyboard 上时,我看到了 containerView,我认为在编写教程时它不存在。
所以我在这里询问这两种方法及其优缺点。
所以基本上是它的 UIViewContainerView。我应该怎么做,为什么?
任何帮助将不胜感激。

最佳答案

当您已经拥有一个 View 并且不需要专门的 View Controller 来构建和处理其中的交互时,您可以使用 UIView

来自 UIView 帮助页面:

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 ---(has)---> UIView


当您需要在已有的 View Controller 中嵌入另一个 View Controller 时,您可以使用 UIContainerView。嵌入式 View Controller 负责为 UIViewContainer 占据的区域返回一个 View 。因此,您的 UIContainerView 知道要使用哪个 View Controller 在其占用的区域内呈现 UIView

来自 UIContainerView 帮助页面:

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

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

SubViewController 返回一个 View 并处理它的事件。

关于ios - UIView 与容器 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24859824/

相关文章:

ios - 如何在 iOS 粘贴板中获取数据以保持多路访问

ios - tableViewCell 中的行在滚动时改变它们的位置

ios - subview 的子层与更高的 subview 重叠

iOS 核心数据怎么会泄露?

ios - 通过 AppStore 控制分发

objective-c - ipad - UISplitViewController 主拆分的奇怪行为

xcode - 如何过滤xcodebuild命令行输出?

ios - 更新应用程序后 UILocalNotification 自定义声音无法正常工作

ios - 在 UIScrollView 中绘制图形

ios - Swift 中的弹出 View