在iOS中绘制一个手势控制可调整大小的圆圈

时间:2014-11-26 12:23:32

标签: ios objective-c iphone cgrect

我想在iOS中画一个圆圈。它可以是图像视图或视图,我想在手势上调整其大小。比如,从外部拖动到中心,圆的半径应该减小,反之亦然。

请注意,我想修复该视图,圆圈或图片的位置。我只是想在拖动时调整尺寸。

2 个答案:

答案 0 :(得分:0)

试试这个

  - (IBAction)pinch:(UIPinchGestureRecognizer *)sender {

    double scale=[sender scale];
  self.view1.frame=CGRectMake(self.view1.frame.origin.x*scale,     self.view1.frame.origin.y*scale, self.view1.frame.size.width*scale, self.view1.frame.size.height*scale);

[self.view1.layer setCornerRadius:5];

}

答案 1 :(得分:0)

试试这个。

- (IBAction)pan:(UIPanGestureRecognizer *)sender {
    for (CALayer *layer in self.imageView.layer.sublayers) {
    [layer removeFromSuperlayer];
    }
    CGPoint scale =[sender locationInView:sender.view];

    CAShapeLayer *circleLayer = [CAShapeLayer layer];

    [circleLayer setBounds:CGRectMake(0.0f, 0.0f, [_imageView bounds].size.width,
                                  [_imageView bounds].size.height)];
    [circleLayer setPosition:CGPointMake(CGRectGetMidX([_imageView bounds]),CGRectGetMidY([_imageView bounds]))];

    UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, CGRectGetWidth(_imageView.frame)+scale.x, CGRectGetHeight(_imageView.frame)+scale.y)];

    [circleLayer setPath:[path CGPath]];

    [circleLayer setStrokeColor:[[UIColor redColor] CGColor]];

    [circleLayer setLineWidth:1.0f];
    [circleLayer setFillColor:[[UIColor clearColor] CGColor]];


    [[_imageView layer] addSublayer:circleLayer];

   }