我正在编写一个APP,这样用户就可以在UIImageView上绘制了
他还可以捏它来放大/缩小。
我已经实现了一个UNDO功能。
所以每次用户绘制描边或缩放图片时,我都会保存UIImage和帧:
ImageWithFrame *imageWithFrame = [[ImageWithFrame alloc]
initWithImageAndFrame:imageViewSubject.image andFrame:imageViewSubject.frame];
[self.tabImageForUndo addObject:imageWithFrame];
我试图保存整个UIImageView在我的数组,但它不起作用,这就是为什么我保存UIImage和帧。
在用户点击UNDO按钮之后,我从数组中获得了最后一个imageWithFrame
ImageWithFrame *imageWithFrame = [self.tabImageForUndo lastObject];
我这样做:
ImageWithFrame *imageWithFrame = [self.tabImageForUndo lastObject];
self.imageViewSubject.frame = CGRectIntegral(imageWithFrame.frame);
self.imageViewSubject.image = imageWithFrame.image;
self.imageViewSubject.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self.tabImageForUndo removeLastObject];
和我清除图形上下文,以防:
UIGraphicsBeginImageContext(self.view.bounds.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextClearRect(context, self.view.bounds);
// clean up context
UIGraphicsEndImageContext();
======================================
我的UIImageView出现了,我做了一个笔画,我做了一个撤销,它工作了。
在我做一个缩放之后,UIImageView被调整大小(缩小或放大),我做一个撤销,所以UIImageView回到它原来的帧
,
如果我再画一笔,图片会变得模糊,UIImageView会变得越来越小。
看这个视频http://tinypic.com/player.php?v=ivbkn5&s=5
我得到了相同的效果(但在整个UIImage上,它是正常的,因为UIImage已经被重新绘制了笔画)
它已经由另一个用户上传,从这个帖子:CGContextStrokePath缩放和绘制图像时不工作
但我不认为它的问题根源与我的问题有关。
请注意,如果我不做缩放,它工作得很好,所以我认为问题是当我在缩放手势后设置旧帧时。
我希望我说得够清楚了。
提前感谢:)
最后我用
UIGraphicsBeginImageContextWithOptions(self.imageViewSubject.bounds.size, self.imageViewSubject.opaque, 0.0);
代替
UIGraphicsBeginImageContext(self.imageViewSubject.bounds.size);