I draw several UIBezierPath in a finger motion based view.
Each time the touch cycle - Start / Move / End - ends, I save the points and create a UIBezierPath , which is stored in an array called bezierArray . I have another array called bezierArrayColors that preserves the colors of each path.
The problem is this. The class uses drawRect . As far as I see, every time drawRect is executed, it should draw all the paths that have ever been created, and the application is now slow.
Now this is my drawRect . I know this is pretty lame, but I don't see how this can be done.
- (void)drawRect:(CGRect)rect { for (int i=0; i<[self.bezierArray count]; i++) { UIBezierPath *aPath = (UIBezierPath*)[self.bezierArray objectAtIndex:i]; UIColor *aColor = (UIColor*)[self.bezierArrayColor objectAtIndex:i]; [aPath setLineWidth:LINE_WIDTH]; [aColor setStroke]; [aPath stroke]; } }
Is there a way to stroke UIBezierPath different colors or possibly width using subfolders? I mean, to change the color, width and other properties of a subpath? This would allow me to use one UIBezierPath with several different subpaths. I would like one bezier to be drawn and left there, without having to redraw every time. What am I missing?
source share