what's the right way to cause a subview to redraw when the device orientation changes?
I have a view controller with a view and one subview. When the device orientation changes the view auto-redraws but the subview doesn't. If I explicitly do [subview setNeedsDisplay] it redraws but I don't have a logical place to put that 开发者_开发百科call in my code. And, since I don't have to explicitly tell the view to redraw, it seems counter-intuitive to tell the subview to redraw. Is there a way to make the subview auto-redraw when the view redraws?
I found that the following works. If it isn't the best approach somebody please give a better way to do it.
Include the following in the subview.m
file, in the initWithFrame:
method
self.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
self.contentMode = UIViewContentModeRedraw;
Even though this works and fits nicely into my code, I don't see why the subview needs these properties set but the view doesn't.
Swift 3/iOS10 syntax:
self.autoresizingMask = [.flexibleWidth, .flexibleHeight]
self.contentMode = .redraw
精彩评论