【问题标题】:How can i remove the circle drawn in iOS?如何删除在 iOS 中绘制的圆圈?
【发布时间】:2013-12-12 21:55:58
【问题描述】:

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

- (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;
    }

}

【问题讨论】:

    标签: ios iphone drawable geometry quartz-core


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-15
      • 2014-04-11
      • 2012-09-19
      • 1970-01-01
      • 2016-02-08
      相关资源
      最近更新 更多