调整使用CoreGraphics绘制的图像的大小

时间:2015-08-03 20:20:21

标签: ios core-graphics

我跟着问题How can I use Core Graphics to draw a circle at my touch location?,现在我的触摸位置有圆圈。

现在我想要用捏手势来调整圆形视图(比如在Photo.app中缩放照片)是否可以使用CoreGraphics对象实现此行为?

这是我的圆圈绘图代码:

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

1 个答案:

答案 0 :(得分:1)

1)首先,您需要设置视图的层次结构(以编程方式或通过Interface Builder)。

例如:

UIViewController
  UIView 
    UISrollView
      UIView
        UIImageView

enter image description here

2)设置自动布局。 (http://natashatherobot.com/ios-autolayout-scrollview/

3)画出你的圆圈。此示例适用于IB设置方法

- (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)设置捏合手势:

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

Pinch To Zoom Effect on UIImageView inside scrollView?

相关问题