我正在开发一个具有两个UIImageViews的绘图应用程序。我想做的是擦除顶部的 UIImageView 以便我可以看到底部的 UIImageView ,反之亦然。我已经实现了所有功能并且它的工作完美但是当我使用UIGestureRecognizer平移/缩放 UIImageView并且我开始擦除图像所以 LineWidth 也被缩放例如:如果我缩放,初始我的橡皮擦宽度设置为 25.0f我的 UIImageView 200% 我的橡皮擦也缩小到 200%,即从 25.0f 到 50.0f,这让一切都变得疯狂。所以我的问题是我怎样才能让我的橡皮擦保持原来的宽度,而不是通过图像缩放来缩小/缩小?
这是我的代码:
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
if (selectedButton == self.Image1Btn)
currentPoint = [touch locationInView:self.ImageCaptureView];
if (selectedButton == self.Image2Btn)
currentPoint = [touch locationInView:self.ImageCaptureView];
if (bottomBarSelectedButton == 1)
{
if (selectedButton == self.Image1Btn)
{
UIGraphicsBeginImageContext(self.Image1.frame.size);
[self.Image1.image drawAtPoint:CGPointZero];
}
if (selectedButton == self.Image2Btn)
{
UIGraphicsBeginImageContext(self.Image2.image.size);
[self.Image2.image drawAtPoint:CGPointZero];
}
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetLineCap(context, kCGLineCapRound);
CGContextSetLineWidth(context, self.lineWidth);
CGContextSetStrokeColorWithColor(context, self.lineColor.CGColor);
CGContextSetBlendMode(context, kCGBlendModeClear);
CGContextBeginPath(context);
CGContextMoveToPoint(context, previousPoint1.x, previousPoint1.y-36);
CGContextAddLineToPoint(context, currentPoint.x, currentPoint.y-36);
CGContextStrokePath(context);
if (selectedButton == self.Image1Btn)
{
self.Image1.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
previousPoint1 = [touch locationInView:self.ImageCaptureView];
}
if (selectedButton == self.Image2Btn)
{
self.Image2.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
previousPoint1 = [touch locationInView:self.ImageCaptureView];
}
}
}
- (IBAction)handlePinch:(UIPinchGestureRecognizer *)recognizer {
CGAffineTransform t = CGAffineTransformScale(recognizer.view.transform, recognizer.scale, recognizer.scale);
recognizer.view.transform = t;
recognizer.scale = 1;
}