我有一个带有 2 个 UIImageView 的应用程序,它们相互重叠。我有 backgroundImg 和 FrontImg。其中 frontImg 可以:通过 UIGestureRecognizers 旋转、移动、缩放。
当我想保存我的 UIImages 时,我会合并它们,但它们会被保存,就好像它们从未被触摸过一样。
有谁知道如何解决这个问题?
这是我的保存方法: UIGraphicsBeginImageContext(self.backgroundImg.image.size);
CGRect rect = CGRectMake(0, 0, self.backgroundImg.image.size.width, self.backgroundImg.image.size.height);
self.frontImg.contentMode = UIViewContentModeScaleAspectFit;
[self.backgroundImg.image drawInRect:rect];
[self.frontImg.image drawInRect:rect];
UIImage *resultingImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
//[imageView3 setImage:resultingImage];
UIGraphicsBeginImageContextWithOptions(self.backgroundImg.bounds.size, NO,0.0);
[self.backgroundImg.image drawInRect:CGRectMake(0, 0, self.backgroundImg.frame.size.width, self.backgroundImg.frame.size.height)];
//UIImage *SaveImage = UIGraphicsGetImageFromCurrentImageContext();
//UIImage *resultingImage = [self mergeImage:self.backgroundImg.image withImage:self.frontImg.image];
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(resultingImage, self,@selector(image:didFinishSavingWithError:contextInfo:), nil);
这些是我的手势功能:
-(IBAction)handlePan:(UIPanGestureRecognizer *)recognizer{
CGPoint translation = [recognizer translationInView:self.view];
recognizer.view.center = CGPointMake(recognizer.view.center.x + translation.x,
recognizer.view.center.y + translation.y);
[recognizer setTranslation:CGPointMake(0, 0) inView:self.view];
}
-(IBAction)handlePinch:(UIPinchGestureRecognizer *)recognizer
{
recognizer.view.transform = CGAffineTransformScale(recognizer.view.transform, recognizer.scale, recognizer.scale);
recognizer.scale =1;
}
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{
return ![gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]];
}
-(IBAction)handleRotate:(UIRotationGestureRecognizer *)recognizer
{
recognizer.view.transform = CGAffineTransformRotate(recognizer.view.transform, recognizer.rotation);
self.frontImg.transform = CGAffineTransformRotate(recognizer.view.transform, recognizer.rotation);
recognizer.rotation = 0;
}