【问题标题】:Resize image drawn with CoreGraphics调整使用 CoreGraphics 绘制的图像大小
【发布时间】:2015-10-26 01:51:13
【问题描述】:

我已关注问题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);

【问题讨论】:

    标签: ios core-graphics


    【解决方案1】:

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

    例如:

    UIViewController
      UIView 
        UISrollView
          UIView
            UIImageView
    

    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?

    【讨论】:

      猜你喜欢
      • 2012-06-15
      • 1970-01-01
      • 2016-05-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-05
      • 2014-06-23
      相关资源
      最近更新 更多