How to move and crop image from masked image?

青春壹個敷衍的年華 提交于 2019-12-13 22:01:41

问题


I have masked image successfully with the help of following link:

How to Mask an UIImageView

In above link there are two images named image.png and mask.png ,

After masking the image i want to crop the result image.

My concern is that I want to crop the image named image.png but mask.png should be stay still as it is. I am using KICropImageView https://github.com/zhangzhixun/CropImageDemo for cropping the Image.

But when I scroll the image my whole result image is scrolling but I just want to scroll image.png not mask.png image.

Any idea how can I do that?


回答1:


You Can Use 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, e.g.
        // 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;
        }];
    }
}


来源:https://stackoverflow.com/questions/31947269/how-to-move-and-crop-image-from-masked-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!