objective-c - iOS UIBezierPath画线如何删除已有的线

浏览:52日期:2023-11-25

问题描述

生成线的代码:self.path = [UIBezierPath bezierPath];

[self.path moveToPoint:from];[self.path addLineToPoint:to];self.pathLayer = [CAShapeLayer layer];self.pathLayer.frame = containerView.bounds;self.pathLayer.path = self.path.CGPath;self.pathLayer.strokeColor = color.CGColor;self.pathLayer.lineWidth = 2.0f;self.pathLayer.lineJoin = kCALineJoinBevel;NSMutableArray *ary = [NSMutableArray arrayWithArray:shapeLayers];[ary addObject:self.pathLayer];shapeLayers = [NSMutableArray arrayWithArray:ary];[containerView.layer addSublayer:self.pathLayer];

如何将上述线删除,在画新线

问题解答

回答1:

self.pathLayer = [CAShapeLayer layer];之前加上

if (self.pathLayer) {[self.pathLayer removeFromSuperlayer]; }

相关文章: