Disable scrolling on touch for a ScrollView

Hello,

I have two scrollview, one inside another, and when i scroll the child scrollview both are scrolling. In order to resolve this issue, i want to disable scrolling on the parent scrollview when any touch event is triggered on the child scrollview.

I tried setEnabled(false) on parent but it disable both scrolview scrolling. I’ve also tried to redefine stopAutoScrollChildren in a scrollview subclass, but even with autoscroll to false scrolling is not disabled.

Any idea ?

Thanks.

Have you tried setSwallowTouches(true) on the child scrollView?

I have just tried but no, it doesn’t work.

Weird that setSwallowTouches(true); fails, although I haven’t tried this before.

What about setTouchEnabled(false); on parent scrollView?

Also, is this CCScrollView or UIScrollView?

OK, I did some looking around the Cocos2d code.

If you are using a CCScrollView, you need to use setTouchMode(Touch::DispatchMode::ONE_BY_ONE);. By default CCScrollView uses ALL_AT_ONCE, which ignores swallowTouches.

If you are using ui::ScrollView, you need to use setPropagateTouchEvents(false); on the child ScrollView. For some reason by default propagateTouchEvents is set to true, which means touches received by a ScrollView will be passed - or propagated - to its parent. Setting this to false means the node keeps the touches to itself.

Hope this helps.

3 Likes

Wow perfect grimfate, it works like a charm, i really appreciate :wink:

(i’m using ui::Scrollview)