39
votes

I've a scrollview and on both sides, I've two buttons left and right.

when i click the scroll view will move left and when right button is clicked it will move right side. My scrollview has 20 buttons (approx) & on click of each button some action is performed.

Everything is perfectly implemented and working fine.

Only thing i couldn't implement is to prevent scrolling by touch. I don't want user to scroll the scrollview manually. How can i prevent it from scrolling by touch and still able to click the buttons inside the scrollview ?

5
This sounds like a major problem you're introducing. You're writing code for a touch oriented device, where people are familiar with scrolling by dragging their fingers, and it's the most natural action. I'm just going to urge you to reconsider your design. Think of your users.jer
If you don't want the touch to work, why are you using a scrollview at all? Just use a normal UIView.fishinear

5 Answers

105
votes

Try setting yourScrollView.scrollEnabled = NO;. That should do exactly what you want.

5
votes

Swift, set scrollView.isScrollEnabled = false and it should work!

4
votes

Swift 3

self.scrollView.isScrollEnabled = false
0
votes

If those buttons are the only interface for users, disable 'User Interaction Enabled' option of the scroll view in the Interface Builder. Or, programmatically, set userInteractionEnabled property to NO.

0
votes

Maybe your issue is that when using UIView.animate and the options:
[.allowUserInteraction], is not set.
After this option set, the scrollview should stop on tap.