I'm trying to add a subpath to my CAShapeLayer
's path, but the changes doesn't show unless I first assing nil
to the path and then I reassign myPath
to the CAShapeLayer
. I've tried with setNeedsRedisplay
but it doesn't works.
This is the code in the LoadView
where myPath
and shapeLayer
are properties:
// The CGMutablePathRef
CGPathMoveToPoint(myPath, nil, self.view.center.x, self.view.center.y);
CGPathAddLineToPoint(myPath, nil, self.view.center.x + 100.0, self.view.center.y - 100.0);
// The CAShapeLayer
shapeLayer = [CAShapeLayer layer];
shapeLayer.path = myPath;
shapeLayer.strokeColor = [UIColor greenColor].CGColor;
shapeLayer.lineWidth = 2.0;
[self.view.layer addSublayer:shapeLayer];
And this is, for example, where I perform the changes to the path. I simply add a new subpath to myPath
:
- (void)handleOneFingerSingleTapGesture:(UIGestureRecognizer *)sender
{
// I add a new subpath to 'myPath'
CGPathMoveToPoint(myPath, nil, self.view.center.x, self.view.center.y);
CGPathAddLineToPoint(myPath, nil, self.view.center.x + 100.0, self.view.center.y + 100.0);
// I must do this to show the changes
shapeLayer.path = nil;
shapeLayer.path = myPath;
}
Anyone knows how to deal with this?. I'm using iOS 5.0.