搜尋

首頁  >  問答  >  主體

objective-c - iOS UIBezierPath畫線如何刪除現有的線

產生線的程式碼:
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];

如何將上述線刪除,在畫新線

为情所困为情所困2833 天前1245

全部回覆(1)我來回復

  • 我想大声告诉你

    我想大声告诉你2017-05-02 09:31:25

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

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

    回覆
    0
  • 取消回覆