gpt4 book ai didi

ios - UIView 与容器 View

转载 作者:技术小花猫 更新时间:2023-10-29 10:41:36 25 4
gpt4 key购买 nike

这就是我要解决的问题。

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com