Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone - UIScrollView... detecting the coordinates of a touch [duplicate]

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.

like image 985
Duck Avatar asked Oct 27 '11 20:10

Duck


1 Answers

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

like image 60
beryllium Avatar answered Oct 02 '22 14:10

beryllium