Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS: UIScrollView detecting Swipe Gesture

I have an UIScrollView which scrolls automatically by using a timer, which scrolls every 3 seconds to the next page (kind of slideshow).

Now I want to implement a function which detects any user interaction, to cancel the timer as soon as the user interacts with the scrollview, so that he can scroll through the scrollview by himself.

What would be the best way to do this? The ScrollView isn't subclassed and is using the UIScrollViewDelegate.

Would be glad for some hints. Cheers.

like image 940
Bins Ich Avatar asked Sep 04 '12 06:09

Bins Ich


People also ask

How to add swipe gesture in iOS Swift?

We can use the createSwipeGestureRecognizer(for:) method in the view controller's viewDidLoad() method to create a swipe gesture recognizer for each direction. We pass the result of createSwipeGestureRecognizer(for:) to the addGestureRecognizer(_:) method.

What is the swipe gesture?

One of the most common gestures you will use on your smartphone or tablet is a swipe. That's where you place your finger on the screen and slide it across the surface. In most instances, the item under your finger will move. How fast the item moves depends on how fast you swipe.


1 Answers

UIScrolViewDelegate has a method to detect when the user "began" dragging:

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
    // disable timer here
}
like image 180
Zhang Avatar answered Nov 15 '22 07:11

Zhang