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.
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.
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.
UIScrolViewDelegate has a method to detect when the user "began" dragging:
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
// disable timer here
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With