我試圖給我的CAShapeLayer
的路徑添加一個子路徑,但這些更改不會顯示,除非我首先將nil
分配到該路徑,然後我將myPath
重新分配給CAShapeLayer
。我試過setNeedsRedisplay
但它不起作用。如何在修改路徑時重繪CAShapeLayer?
這是LoadView
其中myPath
和shapeLayer
是屬性的代碼:
// 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。
不IOS 8.3至少工作 – 2015-05-27 11:25:59