Empty drawRect implementation causes memory warning

不羁的心 提交于 2019-12-22 17:42:02

问题


I have a UIView on which I draw a UIBezierPath by finger. When I rezoom the view (say after a path is drawn) a redraw function is triggered, which rescales the BezierPath:

- (void)redrawPathsWithScale:(float)scale
{
    [_path applyTransform:CGAffineTransformMakeScale(scale, scale)];
    [self setNeedsDisplay];
}

setNeedsDisplay causes drawRect to get called. Now every time I zoom in to a absolute scale somewhere near x6 I immediately get a memory warning, and the App crashes.

My drawRect method looks like this:

- (void)drawRect:(CGRect)rect
{   
    [_path strokeWithBlendMode:kCGBlendModeNormal alpha:1.0];
}

The Curious thing is: Not implementing drawRect at all removes the memory warning. Implementing an empty drawRect still causes a crash!


回答1:


Does adding [super drawRect:rect]; make any difference?

The Apple Documentation for drawRect states:

If you subclass UIView directly, your implementation of this method does not need to call super. However, if you are subclassing a different view class, you should call super at some point in your implementation.

If you're subclassing UIView, you should be fine but it might be worth checking this just in case.



来源:https://stackoverflow.com/questions/13028099/empty-drawrect-implementation-causes-memory-warning

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