如何删除iOS中绘制的圆圈?

时间:2013-12-12 21:55:58

标签: ios iphone drawable geometry quartz-core

我有这个代码,我在屏幕上绘制圆圈,我想删除最后绘制的圆圈。我能做什么?当我点击两次时,代码设置为绘制一个圆圈。我想删除一次点击时绘制的最后一个圆圈。

- (UIBezierPath *)makeCircleAtLocation:(CGPoint)location radius:(CGFloat)radius {

    iOSCircle *circle = [[iOSCircle alloc] init];
    circle.circleCenter = location;
    circle.circleRadius = radius;
    [totalCircles addObject:circle];

    UIBezierPath *path = [UIBezierPath bezierPath];
    [path addArcWithCenter:circle.circleCenter
                radius:circle.circleRadius
                startAngle:0.0
                endAngle:M_PI * 2.0
               clockwise:YES];

    return path;
}

- (IBAction) tapEvent: (UIGestureRecognizer *) sender
{

    CAShapeLayer *shapeLayer = [CAShapeLayer layer];
    shapeLayer.path = [[self makeCircleAtLocation:location radius:2.5] CGPath];
    shapeLayer.strokeColor = [[UIColor redColor] CGColor];
    //shapeLayer.fillColor = nil;
    shapeLayer.lineWidth = 2.5;

    // Add CAShapeLayer to our view

    [self.view.layer addSublayer:shapeLayer];

    // Save this shape layer in a class property for future reference,
    // namely so we can remove it later if we tap elsewhere on the screen.

    self.circleLayer = shapeLayer;
    }

}

1 个答案:

答案 0 :(得分:2)

使用CGPath在不同的CAShapeLayer图层中创建圆圈,并将其添加为view.layer的子图层。这样,您就可以完全控制该圆圈(显示或隐藏它)。