I am drawing several UIBezierPath
s on a view based on finger movements.
Every time a cycle of touches -- Began/Moved/Ended -- completes, I store the points and create a UIBezierPath
that is stored in an array called bezierArray
. I have another array called bezierArrayColors
that stores the colors of each path.
The problem is this. The class uses drawRect
. As far as I can see, every time drawRect
runs, it has to draw all the paths that were ever created and the app is now slow.
This is my drawRect
now. I know it is pretty lame, but I am not seeing 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 a UIBezierPath
with different colors or perhaps widths using subpaths? I mean, to change color, width and other properties of a subpath? That would allow me to use one UIBezierPath
with several different subpaths. I wish one bezier could be drawn and left there without needing to be redrawn every time. What am I missing?