我正在尝试向我CAShapeLayer
的路径添加一个子路径,但是除非我首先分配到nil
路径然后我重新分配myPath
给CAShapeLayer
. 我试过了,setNeedsRedisplay
但它不起作用。
这是LoadView
wheremyPath
和shapeLayer
are 属性中的代码:
// 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];
例如,这是我对路径进行更改的地方。我只是添加一个新的子路径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;
}
任何人都知道如何处理这个?我正在使用 iOS 5.0。