使用GestureRecognizers操作UIImage - 不是UIImageView

Sam*_*cer 0 objective-c uiimageview uiimage ios

使用Pan,Pinch和Rotate等手势识别器,是否可以在UIImageView中操作UIImage?

每当我尝试为UIImage定义手势识别器时,我都会收到错误消息

没有可见的UIImage支持'addGestureRecognizer:'

使用此代码:

UIRotationGestureRecognizer *rotateGesture = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotateImage:)];
[imageStrip addGestureRecognizer:rotateGesture];
Run Code Online (Sandbox Code Playgroud)

无论如何在不转换UIImageView的情况下在UIImageView内部转换UIImage?

Bar*_*ski 5

您可以为任何类型的UIView事件处理方法添加手势识别器,您可以重新绘制UIImage到新创建的方法CGContextRef.这方面必须与转化CGContextRotateCTM,CGContextScaleCTM,CGContextTranslateCTM这将匹配你从手势识别器接收的那些参数来调用.这是艰难的方式.

或者,您可以UIImageView使用图像创建划痕,使用手势识别器对其进行转换,然后将其渲染为a CGContextRef并从此上下文中获取转换后的图像.

当然可行,但不是微不足道的.