layoutsubviews only called once despite the rotation of the device


just what the title says: I create an empty UIView subclass and I add a subview to it, I create an empty layoutSubviews method and I add a breakpoint there. Then I build the project and the simulation stops when loading the view at that point in the layoutSubviews method. Everything is fine so far. I continue the simulation and I rotate the device (assuming that the view controller is set to allow any orientation) but layoutSubviews is never called again, despite I can see how my object is rotating. Any idea?

OK, i will simplify my question: How do I create a custom UIView with some subviews and make it responsive to the device orientation? I don't need to use drawRect or anything, just subclass UIView, add a couple of subViews and handle them when the device is rotating.

Did you try setting the autoresizingMask on the UIView? For example like below:

someView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

From the UIView documentation:

'When a view’s bounds change, that view automatically resizes its subviews according to each subview’s autoresizing mask'

If you set the autoresizingMask to something other than None it should mean that the layoutSubviews method is always called when the views bounds change.