UIBezierPath too many paths = too slow?
Posted
by
HHHH
on Stack Overflow
See other posts from Stack Overflow
or by HHHH
Published on 2012-10-12T08:36:51Z
Indexed on
2012/10/12
9:37 UTC
Read the original article
Hit count: 181
I have a loop in which I'm adding many (10000+) lines to a UIBezierPath. This seems to be fine, but once I try and render the bezierpath, my device becomes extremely slow and jerky. Is this because I've added too many lines to my path?
Adding lines to UIBezierPath - simplified: (this seems fine)
[path moveToPoint:CGPointZero];
for (int i = 0; i < 10000; i++ ) {
[path addLineToPoint:CGPointMake(i, i)];
}
Rendering BeizerPath (Suggested by Rob) - this seems slow.
- (void)drawBezierAnimate:(BOOL)animate
{
UIBezierPath *bezierPath = path;
CAShapeLayer *bezier = [[CAShapeLayer alloc] init];
bezier.path = bezierPath.CGPath;
bezier.strokeColor = [UIColor blueColor].CGColor;
bezier.fillColor = [UIColor clearColor].CGColor;
bezier.lineWidth = 2.0;
bezier.strokeStart = 0.0;
bezier.strokeEnd = 1.0;
[self.layer addSublayer:bezier];
if (animate)
{
CABasicAnimation *animateStrokeEnd = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
animateStrokeEnd.duration = 100.0;
animateStrokeEnd.fromValue = [NSNumber numberWithFloat:0.0f];
animateStrokeEnd.toValue = [NSNumber numberWithFloat:1.0f];
[bezier addAnimation:animateStrokeEnd forKey:@"strokeEndAnimation"];
}
}
Qs:
1) Is this because I'm adding too many paths too quickly?
2) I want to eventually draw many different lines of different colors, so I assume I would need to create multiple (10000+) UIBezierPaths - would this help or greatly slow the device as well?
3) How would I get around this?
Thanks in advance for your help.
© Stack Overflow or respective owner