简体   繁体   中英

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 ?

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

Swift ,设置scrollView.isScrollEnabled = false就可以了!

斯威夫特 3

self.scrollView.isScrollEnabled = false

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM