user1284151
user1284151

Reputation: 885

Resize image drawn with CoreGraphics

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);

Upvotes: 1

Views: 251

Answers (1)

Klevison
Klevison

Reputation: 3484

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?

Upvotes: 1

Related Questions