Why do I not need to specify autoresizingMask for my custom UIViewController's root view?

允我心安 提交于 2019-12-12 02:47:43

问题


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.)


回答1:


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.



来源:https://stackoverflow.com/questions/9039991/why-do-i-not-need-to-specify-autoresizingmask-for-my-custom-uiviewcontrollers-r

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!