0

I have an image inside a UIImageView, which has a gesture for zooming, as you can see from the code.

I want to be able to insert clickable areas of the image, not the screen, so if I click an image point with minimum or maximum zoom zoom I always return the same value.

I could tell by the UIGestureRecognizer if I can do? Why can not I figure out whether I work or not.

thanks

My code:

UITapGestureRecognizer *twoFingerTap = [[UITapGestureRecognizer alloc] initWithTarget:self         action:@selector(handleTwoFingerTap:)];
[twoFingerTap setNumberOfTouchesRequired:2];
[img addGestureRecognizer:twoFingerTap];
float minimumScale = 0.4;//This is the minimum scale, set it to whatever you want. 1.0 = default
scroll.maximumZoomScale = 4.0;
scroll.minimumZoomScale = minimumScale;
scroll.zoomScale = minimumScale;
[scroll setContentMode:UIViewContentModeScaleAspectFit];
[img sizeToFit];
[scroll setContentSize:CGSizeMake(img.frame.size.width, img.frame.size.height)];

[control setSelectedSegmentIndex:0];
[control addTarget:self
            action:@selector(action:)
  forControlEvents:UIControlEventValueChanged];

//THIS IS MY RECOGNIZER ON IMAGE
UIGestureRecognizer *recognizerImage = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapImage:)];
[(UITapGestureRecognizer *)recognizer setNumberOfTapsRequired:2];
[img addGestureRecognizer:recognizer];
}


- (void)tapImage:(UITapGestureRecognizer *)recognizer {

    CGPoint location = [recognizer locationInView:self.view];
    NSLog(@"x %f y %f",location.x, location.y);
}
Xu Yin
  • 3,932
  • 1
  • 26
  • 46
user3019841
  • 49
  • 1
  • 6
  • Ok, you've outlined the problem. What have you done to solve it? You need to come up with logic that uses a proportion of the original image size to the current image size to translate view coordinates into image coordinates. – Duncan C Feb 05 '14 at 23:14
  • http://stackoverflow.com/questions/9008975/how-to-tap-to-zoom-and-double-tap-to-zoom-out-with-uiscrollview/9009554#9009554 – GWed Feb 17 '14 at 16:11

2 Answers2

1

Try an using the imageView as a reference:

CGPoint location = [recognizer locationInView:recognizer.view];

Let me know if that works.

jbouaziz
  • 1,484
  • 1
  • 12
  • 24
0
- (void)tapImage:(UITapGestureRecognizer *)recognizer {

    // CGPoint location = [recognizer locationInView:self.view]; // self.view will always be the same. You need to use the view on which the user tapped. It's `recognizer.view`

    CGPoint location = [recognizer locationInView:recognizer.view]; 

    NSLog(@"x %f y %f",location.x, location.y);
}

If you want to learn more about UIGestures then i've got a excellent tutorial for you.

http://www.raywenderlich.com/6567/uigesturerecognizer-tutorial-in-ios-5-pinches-pans-and-more

Akshit Zaveri
  • 4,166
  • 6
  • 30
  • 59