ios - User Interactive Core Graphics line without memory warning/crash -
I am working on a project that includes users who interact with straight lines in the top of UIIMage, Has been included. There is "handle" at each end of the line to interact with the user. When dragged, setNeedsDisplay
is called and the line is drawn again after the length and angle change
I redraw the line using the following code I am here. It is very simple, but I think core graphics may not be the right approach to this.
The following drawRect
:
- (zero) drones {CGContextRef ctx = UIGraphicsGetCurrentContext (); CGContextSaveGState (ctx); CGContextBeginPath (ctx); CGContextSetStrokeColorWithColor (CTX, [[UIColor BlueColor CGColor]); CGContextSetLineWidth (CTX, 6.0); CGContextSetAlpha (CTX, 1.0); CGContextMoveToPoint (ctx, pointA.x, pointA.y); CGContextAddLineToPoint (ctx, pointB.x, pointB.y); CGContextStrokePath (ctx); CGContextRestoreGstate (ctx); }
Edit: The problem I am facing is that when I pull this item quickly, I spike memory usage, I get memory warning, and then It crashes. Xcode says, "End due to memory pressure".
Thank you in advance for your thoughts!
solution The size of the UIView was very large. Calling on such a large UIView setNeedsDisplay
will cause memory nail and crash. Apple limits UIView to 1024x1024. Although it is no longer the limit, they still recommend keeping the size down to keep the memory footprint low.
Source:
Comments
Post a Comment