0

I have an image showed in uiimage view. If i touch some where in the screen, is there any method to know which point is touched in the image. i want to take the co-ordinates with respect to image, not screen co-ordinates. I want to do this without using any 3rd party library. Please suggest if there are any methods.

4

4 回答 4

1

像这样尝试,重要说明userInteractionEnable=YES默认设置为您的图像视图用户交互设置为图像视图的 NO。

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *touch = [[event allTouches] anyObject];
    if([[touch view] isKindOfClass:[UIImageView  class]]){
        CGPoint point= [touch locationInView:touch.view];
        NSLog(@"%f%f",point.x,point.y);
    }

}
于 2013-08-23T10:48:07.897 回答
0

一旦你从 UIImageView 触摸事件中获得相对坐标(我假设你正在使用 UIImageView 并为 Image 设置它的 Image 属性)。然后您可以使用 1/UIImageView.image.scale 与相对触摸坐标相乘并获得该图像的绝对坐标。

基本上,您的原始图像会根据 UIImageView 的大小而倾斜或缩放,因此您需要对其进行反转。

于 2013-08-23T10:36:30.090 回答
0

已经提出并回答了类似的问题。他们中的一些人在这里指出以帮助将来的人..

  1. https://stackoverflow.com/a/10212280/4140018
  2. https://stackoverflow.com/a/17200285/4140018
  3. http://b2cloud.com.au/tutorial/uiimageview-transforming-touch-coordinates-to-pixel-coordinates/
于 2015-08-21T06:19:09.630 回答
-1

要将点从一个视图转换为另一个视图,可以使用convertPoint:fromView:convertPoint:toView:方法。

于 2013-08-23T10:30:50.533 回答