2

I am working on an iOS map app and it includes interactive map. The interactive map is a subclass of UIImageView and placed on a scrollView. My view hierarchy is shown below:
View hierarchy
When user taps some part of the map, ViewController performs animated segue (like zoom-in to that area of the map). I can start segue from any point of the screen, but to do this properly, I need exact coordinates of user's tap relative to the screen itself. As ImageView is put at the top of ScrollView, it uses different coordinate system, larger than screen size. No matter, which area of map has ben tapped, what matters is the tapped CGPoint on the screen (physical).

ImageView uses its own code to get coordinates of a tap:

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    [super touchesEnded:touches withEvent:event];

    // cancel previous touch ended event
    [NSObject cancelPreviousPerformRequestsWithTarget:self];

    CGPoint touchPoint  = \
        [[touches anyObject] locationInView:self];

    NSValue*    touchValue =\
        [NSValue
         valueWithCGPoint:touchPoint];

    // perform new one
    [self
     performSelector:@selector(_performHitTestOnArea:)
     withObject:touchValue
     afterDelay:0.1];
}

And the case if I place gesture recognizer, it works, but ImageView can't get any touches and, therefore, call segue.

The code for gesture recognizer, I attempted to use:

UITapGestureRecognizer *rec = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapRecognized:)];
[someView addGestureRecognizer:rec];
[rec release];

// elsewhere
- (void)tapRecognized:(UITapGestureRecognizer *)recognizer
{
    if(recognizer.state == UIGestureRecognizerStateRecognized)
    {
        CGPoint point = [recognizer locationInView:recognizer.view];
        // again, point.x and point.y have the coordinates
    }
}  

So, is there any way to get two coordinates in different reference systems?, or to make these recognizers work simultaneously without interfering each other?

Solved
I use this code to convert touched point from one view's reference system to

CGPoint pointInViewCoords = [self.parentView convertPoint:self.imageView.touchPoint fromView:self.imageView];

Where self.parentView is "View" on hierarchy image - with the size of the screen.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Richard Topchii
  • 7,075
  • 8
  • 48
  • 115
  • 1
    http://stackoverflow.com/questions/4353150/cgpoint-relative-to-view – skyylex Jul 16 '14 at 20:13
  • Thanx, but it doesn't help. something wrong with conversion, it gives "unreal" coordinates which seem to be dependent on the image size. And what i Need is coordinates exactly relative to the device size. – Richard Topchii Jul 16 '14 at 20:28
  • What is the depth of the UIView hierarchy? You can try to override hitView: for UIImageView to skip some events and catch them at other level. http://stackoverflow.com/questions/7719412/how-to-ignore-touch-events-and-pass-them-to-another-subviews-uicontrol-objects – skyylex Jul 16 '14 at 20:47
  • Also to the first link, you can try to convert CGPoints to the [UIApplication sharedApplication] keyWindow] that fills all place? – skyylex Jul 16 '14 at 20:50
  • I was mistaken, after some manipulations it started to work. Look the question, I will post the solution. – Richard Topchii Jul 16 '14 at 21:49

0 Answers0