iPhone - UIScrollView... detecting the coordinates of a touch

11,560

You can do it with gesture recognizers. For detect single tap location use UITapGestureRecognizer

UITapGestureRecognizer *tapRecognizer = [[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)] autorelease];
[myScrollView addGestureRecognizer:tapRecognizer];

- (void)tapAction:(UITapGestureRecognizer*)sender{ 
    CGPoint tapPoint = [sender locationInView:myScrollView];
    CGPoint tapPointInView = [myScrollView convertPoint:tapPoint toView:self.view];
}

To convert that tapPoint to self.view you can use convertPoint:toView: method in UIView class

Share:
11,560
Duck
Author by

Duck

Updated on June 23, 2022

Comments

  • Duck
    Duck almost 2 years

    Possible Duplicate:
    UIScrollview getting touch events

    Is it possible to detect where in a UIScrollView the finger touched?

    I mean, suppose the user uses his finger in this way: taps and scroll, lifts the finger and again, taps and scroll, etc. Is it possible to know the CGPoint where the taps happened in relation to the self.view the scroller is in? The scroller occupies the whole self.view.

    Thanks.