为什么我不需要为自定义UIViewController的根视图指定autoresizingMask? [英] Why do I not need to specify autoresizingMask for my custom UIViewController's root view?

查看:100
本文介绍了为什么我不需要为自定义UIViewController的根视图指定autoresizingMask?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的自定义视图控制器中,我重写了loadView以编程方式设置我的视图层次结构.为了支持自动旋转,我为层次结构中所有视图的autoresizingMask属性分配了一个适当的值-根视图(我分配给self.view的视图除外)除外.尽管有这种遗漏,但调整自动旋转大小仍然可以完美地完成工作(最终能够说出☺感觉很好).我已经在各种模拟器以及iPhone和iPad设备上进行了测试.

In my custom view controller I override loadView to programmatically set up my view hierarchy. To support auto-rotation I assign an appropriate value to the autoresizingMask property of all views in the hierarchy - except for the root view (the one that I assign to self.view). Despite this omission, resizing on auto-rotation works perfectly (it feels so good to be finally able to say this ☺). I have tested in various simulators, and also on my iPhone and iPad devices.

有人知道为什么会这样吗?这种行为仅仅是运气",还是苹果在某处正式记录了这种行为?

Does anyone know why this is the case? Is this behaviour just "luck", or is it officially documented by Apple somewhere?

(注意:我主要是出于好奇而问,请不要告诉我去解决它,它只是一行代码"-我已经这样做了.)

(Note: I'm asking mostly out of curiosity, please don't tell me to "go fix it, it's just one line of code" - I have already done so.)

推荐答案

autoresizesSubviews/autoresizingMask定义超级视图与子视图的关系.如果UIViewController支持旋转,则控制器将在旋转时管理视图的框架,而与任何自动调整大小属性无关.

autoresizesSubviews/autoresizingMask define a superview-to-subview relationship. In the case of a UIViewController that supports rotation, the controller is managing the view's frame on rotation independent of any autoresize properties.

这篇关于为什么我不需要为自定义UIViewController的根视图指定autoresizingMask?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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