如何以编程方式在Imageview2 ios中显示ImageView1的TouchLocation

时间:2014-10-30 07:40:23

标签: ios

我在Imageview1中显示图像。在触摸我能够得到X,Y CO坐标的触摸点,现在我想在另一个imageview2中显示触摸点周围的图像区域?我的参考是Snap seed应用功能选择性调整放大点击imageView1上的按钮点。

1 个答案:

答案 0 :(得分:1)

我认为你想要显示第一张图像到第二张图像的部分取决于Touch!你必须在第一张图片上获得触摸位置,

UITouch *touch = [touches anyObject];
CGPoint point = [touch locationInView:image1];

猜猜你想要展示的图像是

UIImage *imageToCrop = [UIImage imageNamed:@"Abc.png"];

首先从点

创建矩形
CGRect cropRect = CGRectMake(point.x, point.y,point.x-20,point.y-20);
UIImage *cropImage = [self crop:imageToCrop Rect:cropRect];
image2.image = cropImage;

(* image2是ImageView);

调用此函数返回给定rect的裁剪图像

-(UIImage*)crop:(UIImage *)Imagecrop Rect:(CGRect)rect {

CGImageRef imageRef = CGImageCreateWithImageInRect([Imagecrop CGImage], rect);
UIImage *result = [UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef);
return result;
}

所有这些你必须要做的事情Touch Events! 愿这帮助你!

你还应该看看This Project