-1

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?

Community
  • 1
  • 1
Piyush
  • 1,534
  • 12
  • 32
  • How do you _scroll_ an _image_? – matt Aug 11 '15 at 17:03
  • i'm using https://github.com/zhangzhixun/CropImageDemo for cropping and in that image is scrolling using UIScrollView. – Piyush Aug 11 '15 at 17:24
  • Mmmmmm, no. What is inside the scroll view is an _image view_. So you scroll the scroll view in order to see a different part of the _image view_. - In any case that is very old code - it doesn't even use ARC! - so I really can't recommend using it wholesale. You are better off to start from scratch. – matt Aug 11 '15 at 17:29
  • @Matt thanks for your advice but i just want to know that can i separate masked image for example i have masked image named image.png on image named masked.png after masking i got result image and after that i want to fire action on my original image which is image.png. so is there any way to do that? – Piyush Aug 11 '15 at 19:18
  • Let's say you have view A and its subview view B. Put the mask on view A. It masks view A _and_ view B, because view B is inside view A. Now if you move view B the mask doesn't move because it is attached to view A. – matt Aug 11 '15 at 21:21

1 Answers1

0

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;
        }];
    }
}
Piyush
  • 1,534
  • 12
  • 32
Hitesh Boricha
  • 114
  • 1
  • 11