问题
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