eharo2
eharo2

Reputation: 2642

Get the UIScrollView translation in view as the scroll happens?

I am trying to intercept the locationInView from the UIScrollView.panGestureRecognizer as the scroll is happening.

I was able to get the initial touch coordinates (when the scroll begins) implementing the following code inside the delegate method

#pragma mark UIScrollViewDelegate
- (void) scrollViewWillBeginDragging:(UIScrollView *)scrollView {
CGPoint point = [scrollView.panGestureRecognizer locationInView:scrollView];
NSLog(@"%@", NSStringFromCGPoint(point));}

Is there a way to get the coordinates continuously as the scroll is happening? I understand that the scrollView.panGestureRecognizer is a UIPanGestureRecognizer @property of the UIScrollView object, so there should be a panGestureDetected @selector somewhere.

Thx in advance.... e

Upvotes: 1

Views: 1538

Answers (1)

Chris
Chris

Reputation: 1673

Add the UIScrollViewDelegate method:

- (void)scrollViewDidScroll:(UIScrollView *)scrollView

And in there you can access the scrollView while it is scrolling. If you are not using a view that subclasses UIScrollView, be sure to explicitly implement the UIScrollViewDelegate. I assume that you should not have to since the delegate method in your question is being called but I just thought I would point that out.

Be sure you really want to use the locationInView: method because it will return the point of the gesture and not the contentOffset of the UIScrollView. In other words, the gesture point may be outside of the desired range, where the contentOffset is in direct relation to the UIScrollView object.

EDIT:

Just as an FYI, the method will be called a lot, so make sure you are not doing any heavy processing every time the method is called.

Upvotes: 3

Related Questions