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

前端 未结 3 1302
遥遥无期
遥遥无期 2020-12-10 01: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 c

相关标签:
3条回答
  • 2020-12-10 02:21

    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 讨论(0)
  • 2020-12-10 02:27

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

    0 讨论(0)
  • 2020-12-10 02:29
    [myView setContentMode:UIViewContentModeRedraw];
    

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

    0 讨论(0)
提交回复
热议问题