问题
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