1

I've followed question How can I use Core Graphics to draw a circle at my touch location? and now I have circles in my touch position.

Now I'd like to have a pinch gesture to resize view with circles (like zooming photos in Photo.app) Is it possible to achieve this behavior with CoreGraphics objects?

Here is my circle drawing code:

CGContextRef ctx= UIGraphicsGetCurrentContext();

CGContextSaveGState(ctx);

CGContextSetLineWidth(ctx,5);
CGContextSetRGBStrokeColor(ctx,0.8,0.8,0.8,1.0);
CGContextAddArc(ctx,20,40,30,0.0,M_PI*2,YES);
CGContextStrokePath(ctx);
Community
  • 1
  • 1
user1284151
  • 875
  • 4
  • 12
  • 23

1 Answers1

1

1) First of all, you need to setup your views's hierarchy (programatically or via Interface Builder)..

For example:

UIViewController
  UIView 
    UISrollView
      UIView
        UIImageView

enter image description here

2) Setup autolayout. (http://natashatherobot.com/ios-autolayout-scrollview/)

3) Draw your circle. This example is for IB setup approach

- (UIImage *)drawCircle {
  CGContextRef ctx= UIGraphicsGetCurrentContext();
  CGContextSaveGState(ctx);
  CGContextSetLineWidth(ctx,5);
  CGContextSetRGBStrokeColor(ctx,0.8,0.8,0.8,1.0);
  CGContextAddArc(ctx,20,40,30,0.0,M_PI*2,YES);
  CGContextStrokePath(ctx);

  return UIGraphicsGetImageFromCurrentImageContext()
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.imageView.image = [self drawCircle];
}

4) Setup Pinch Gestures:

https://developer.apple.com/library/ios/documentation/WindowsViews/Conceptual/UIScrollView_pg/ZoomZoom/ZoomZoom.html

Pinch To Zoom Effect on UIImageView inside scrollView?

Community
  • 1
  • 1
Klevison
  • 3,342
  • 2
  • 19
  • 32