gpt4 book ai didi

iphone - self.view = someController.view 与 [self.view addSubview :someController. view]

转载 作者:行者123 更新时间:2023-12-03 21:19:00 27 4
gpt4 key购买 nike

我正在尝试找出我遇到的错误。最初,我的同事只是使用

将 View 添加到 subview 中
[self.view addSubview:someController.view];

来自当前ViewController。这看起来不错,但有点迟缓。我想根据需要延迟加载 View 并使用我在这篇文章中得到的建议:How to optimize performance in view controller navigation with UISegmentedControl and UITabBarController

通过设置 View ,它确实可以更快地工作

self.view = someController.view

但是, View 的高度不正确。我正在尝试调试正在发生的事情,但我不确定我是否理解将新 View 添加为 subview 与将其设置为当前 View 之间的区别。我认为将其添加到我当前的 View 中,或将其添加为 subview 将占用相同的大小,但我一定错过了一些东西。任何帮助表示赞赏。谢谢!

最佳答案

self.view = someController.view,表示该 View 被新 View 替换。这意味着新 View 将具有 someController.view 中设置的所有属性。
将 View 添加为 subview 意味着新 View 必须面对父 View 中已设置的所有内容(从框架、大小和边距开始)。
每种方法都有不同的含义,并且应该用于不同的结果。
我不知道哪一个是你的,但如果你只想拥有与被替换 View 相同大小的替换 View ,你可以使用 someController.view.frame = self.view.frame; 在添加或替换旧 View 之前。

关于iphone - self.view = someController.view 与 [self.view addSubview :someController. view],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6849338/

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