简体   繁体   中英

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM