An empty drawRect implementation raises a memory warning

I have a UIView on which I draw a UIBezierPath with my finger. When I re-view the view (say, after the path is drawn), the redraw function is launched, which retells BezierPath:

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

setNeedsDisplay calls the drawRect call. Now every time I approach the absolute scale somewhere near x6, I immediately get a memory warning and the application crashes.

My drawRect method is as follows:

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

Curious: does not implement drawRect at all removes the warning about memory. Implementing an empty drawRect still fails!

+2
source share
1 answer

Does adding [super drawRect:rect]; ?

Apple Documentation for drawRect:

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

If you subclass UIView, you should be fine, but it might be worth checking out just in case.

+1
source

Source: https://habr.com/ru/post/1441519/


All Articles