self.view = someController.view 与 [self.view addSubview:someController.view] [英] self.view = someController.view versus [self.view addSubview:someController.view]

查看:24
本文介绍了self.view = someController.view 与 [self.view addSubview:someController.view]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to figure out a bug I have. Originally, my coworker just added views to the subview using the

[self.view addSubview:someController.view];

来自当前的 ViewController.这看起来不错,但有点迟钝.我想根据需要延迟加载视图并使用我在这篇文章中得到的建议:如何优化使用 UISegmentedControl 和 UITabBarController 在视图控制器导航中的性能

from the current ViewController. This looks right, but is kind of sluggish. I wanted to lazily load the views as needed and use the advice I got in this post: How to optimize performance in view controller navigation with UISegmentedControl and UITabBarController

只需像这样设置视图就可以更快地工作

It does work faster by just setting the view like

self.view = someController.view

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

however, the view's height is incorrect. I'm trying to debug what is happening, but I'm not sure if I understand the difference between adding the new view as a subview, vs setting it to my current view. I would think that adding it on my current view, or adding it as a subview would take up the same size, but I must be missing something. Any help is appreciated. Thanks!

推荐答案

AFAIK 当视图作为子视图添加时,父视图会查看其自动调整大小掩码并相应地调整视图大小.与将视图本身替换"为另一个完全不进行大小调整的视图不同.

AFAIK when view is added as a subview, the parent view looks at its autosizing mask and adjusts the view size accordingly. Not unlike "replacing" the view itself with another view where size adjustment does not take place at all.

这篇关于self.view = someController.view 与 [self.view addSubview:someController.view]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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