Question

I have a scrollview, which automatically advances every 3 seconds to the next "page" (page control also used). However, once the user touches the scrollview, I want to stop the auto-advancing.

I have subclassed the scrollview. I can detect touchesBegan in the subclass, but touchesMoved is not called, so I can't tell if the user has manually swiped the scrollview. I can't use scrollviewDidScroll, because that gets called when I set the contentOffset when the auto-advance timer fires.

So what are my other options for detecting touches? Why isn't touchesMoved called on the scrollview subclass?

Was it helpful?

Solution

Thank you for the suggestions. They helped me stumble upon this easy solution:

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
    [self.scrollTimer invalidate];
}

OTHER TIPS

You may want to look into the following delegate method:

- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView

Per Apple:

The scroll view calls this method at the end of its implementations of the UIScrollView and setContentOffset:animated: and scrollRectToVisible:animated: methods, but only if animations are requested.

So that delegate method is only called when programatic scrolling occurs. You could set up your autoscroll call in that method, only calling it if some BOOL is false. Setting that BOOL to true in your touch event.

Or something completely different =]

It is a useful delegate method though.

~ Good luck

The scrollview probably nominates a subview to receive touch input — UIKit objects are very fussy about this sort of thing and generally can't even handle forwarded events.

What you probably want to do is to key-value observe either tracking or dragging (and it sounds like you want the latter). If the relevant property changes to true then you know the user has initiated scrolling.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top