Satyam
Satyam

Reputation: 15904

iphone - prevent uiscrollview from scrolling by touch

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 ?

Upvotes: 40

Views: 36690

Answers (5)

7RedBits.com
7RedBits.com

Reputation: 483

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.

Upvotes: 0

Chris Jones
Chris Jones

Reputation: 857

Swift 3

self.scrollView.isScrollEnabled = false

Upvotes: 6

Hemang
Hemang

Reputation: 27072

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

Upvotes: 6

MHC
MHC

Reputation: 6405

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.

Upvotes: 0

mrueg
mrueg

Reputation: 8225

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

Upvotes: 110

Related Questions