Become a MacRumors Supporter for $25/year with no ads, private forums, and more!

dantastic

macrumors 6502a
Original poster
Jan 21, 2011
572
678
I'm looking for some input here, what's the best way to go about this.

I have a slideshow controller, a bunch of UIImageViews along a UIScrollView.

I can scroll right and left using swipes but when I single tap I start a NSTimer based slideshow that scrolls the view so much every repeat. another single tap invalidates the timer.

The problem is that the user can still swipe the screen and it messes up the slideshow animation.

I need to be able to discard any gesture that is not a tap. I can't disable userinteraction, I can't disable scrolling.

I have tried to disable all gestures that aren't tap recognizers
Code:
for (UIGestureRecognizer * gestureRecognizer in [self.scrollView gestureRecognizers]) {
		if (![gestureRecognizer isKindOfClass:[UITapGestureRecognizer class]]) {
			[gestureRecognizer setEnabled:NO];
		}
	}

I have tried to create a generic gesture and have that fail all but taps
Code:
for (UIGestureRecognizer * gestureRecognizer in [self.scrollView gestureRecognizers]) {
		if (![gestureRecognizer isKindOfClass:[UITapGestureRecognizer class]]) {
			[gestureRecognizer requireGestureRecognizerToFail:self.gesture];
		}
	}
 

nickculbertson

macrumors regular
Nov 19, 2010
226
0
Nashville, TN
This might do the trick.

Code:
//in your single tap method
scrollView.scrollEnabled = NO;

//in your timer invalidate method
scrollView.scrollEnabled = YES;

Nick
 
Comment

dantastic

macrumors 6502a
Original poster
Jan 21, 2011
572
678
Nick, I haven't actually tested that one. I saw it on the auto-complete list but didn't want to test it as it sounded like it would disable scrolling completely and my slideshow is scrolling programmatically so that would have been silly. :)
After you posted this though I had a look at the documentation and it clearly says that it disables touches.

I will have to try this. thanks!

EDIT:
Works! That's exactly what I was looking for!
 
Last edited:
Comment
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.