如何移动和裁剪蒙版图像的图像?

我借助以下链接成功遮盖了图片:

如何屏蔽UIImageView

在上面的链接中有两个图像image.pngmask.png

掩盖图像后,我想裁剪结果图像。

我担心的是我想裁剪名为image.png的图像,但是mask.png应该保持原样。 我正在使用KICropImageView https://github.com/zhangzhixun/CropImageDemo裁剪图像。

但是当我滚动图像时,我的整个结果图像滚动,但我只想滚动image.pngmask.png图像。

任何想法我怎么能做到这一点?

您可以使用PanGesture ..

 - (void)viewDidLoad { [super viewDidLoad]; UIPanGestureRecognizer *pan1 = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePanImage:)]; self.imageview.userInteractionEnabled = YES; [self.imageview addGestureRecognizer:pan1]; } **after called Method handlePanImage..** - (void)handlePanImage:(UIPanGestureRecognizer *)sender { static CGPoint originalCenter; if (sender.state == UIGestureRecognizerStateBegan) { originalCenter = sender.view.center; sender.view.alpha = 0.8; [sender.view.superview bringSubviewToFront:sender.view]; } else if (sender.state == UIGestureRecognizerStateChanged) { CGPoint translation = [sender translationInView:self.view]; sender.view.center = CGPointMake(originalCenter.x + translation.x, originalCenter.y + translation.y); } else if (sender.state == UIGestureRecognizerStateEnded || sender.state == UIGestureRecognizerStateCancelled || sender.state == UIGestureRecognizerStateFailed) { // do whatever post dragging you want, eg // snap the piece into place [UIView animateWithDuration:0.2 animations:^{ CGPoint center = sender.view.center; center.x = round(center.x / 50.0) * 50.0; center.y = round(center.y / 50.0) * 50.0; sender.view.center = center; sender.view.alpha = 1.0; }]; } }