开发者

iPhone SDK: How to trigger drawRect on UIView subclass after orientation change?

开发者 https://www.devze.com 2022-12-24 14:59 出处:网络
I am subclassing a UIView and overwrite the drawRect method. I\'m noticing that the view\'s drawrect is only being called when the view first loads. After that it is never called again. How to I make

I am subclassing a UIView and overwrite the drawRect method. I'm noticing that the view's drawrect is only being called when the view first loads. After that it is never called again. How to I make sure it gets called after an orientation change? I've tried calling setNeedsDisplay on the view be开发者_StackOverflow社区fore and after the rotation and that doesn't do it.


[myView setContentMode:UIViewContentModeRedraw];

You can set this in IB as well (i.e., set mode to "redraw")


This was a bug related to something completely different. setNeedsDisplay does indeed cause drawRect to be called.


to answer this and the other 94,000 similiar questions about view rotation/drawrect funkiness,

-(id)initWithFrame:(CGRect)frame
{
    if(self=[super initWithFrame:frame]) {
        self.autoresizesSubviews=YES;
        self.autoresizingMask=UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
    }
    return self;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消