Why do I not need to specify autoresizingMask for

2019-09-16 18:55发布

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条回答
再贱就再见
2楼-- · 2019-09-16 19:45

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.

查看更多
登录 后发表回答