Calling setNeedsDisplay in layoutSubviews?

别等时光非礼了梦想. 提交于 2019-12-10 15:17:23

问题


Consider a view with a custom background that is drawn in drawRect:. If the view changes size, the background need to be redrawn.

Is this a bad idea?

- (void) layoutSubviews
{
    [super layoutSubviews];
    [self setNeedsDisplay];
}

If it is, what would be a better alternative considering I can't control who changes the size of the view?


回答1:


Dont do that, it's not necessary. Set the contentMode of the view to UIViewContentModeRedraw:

UIViewContentModeRedraw

Redisplays the view when the bounds change by invoking the setNeedsDisplay method. Available in iOS 2.0 and later. Declared in UIView.h.

This will achieve the same effect.



来源:https://stackoverflow.com/questions/13434794/calling-setneedsdisplay-in-layoutsubviews

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!