问题
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