Buttons and Menus in ccui.ScrollView

When you place a Button or Menu in ccui.ScrollView then touchBegin on the button will fire the event handler (the button is pressed).

This is not desired in case that user only meant to scroll the view.

I want to fire the Button event only if user taps on it. That means that the distance traveled between touchBegin and touchEnd position is short enough to be considered a tap.

What would be the best way to implement it? Or is it already possible with some special settings?

Thanks!
–Josef

Did you ever figure this out? I’m in a similar situation except that I’d like the view to still scroll even if they’ve dragged their finger starting from a button. Currently I can’t get it to scroll in this case. Any suggestions?

Hi @pepeek

When you add a Button into a ccui.ScrollView, if you press the button and start to drag the scrollview, the tap event shouldn’t be fired. But if the drag distance is short, the tap event will fire.

And in ccui.scrollView’s implementation, there is a _childFocusCancelOffset(5.0f) member variable which is controlling how far the drag event shouldn’t trigger tap event.

If the default value is not good for you, you could change this value.

Note: This value is in cocos/ui/UIScollView.cpp.

The hardcoded value here is not good, we need to change it with screen DPI in consideration.

@owen that’s some great information, thanks.

BTW if anyone is wondering what my issue was, I had a menu with menu buttons inside my ScrollView. ScrollView’s don’t work so well with these. I think it has something to do it there being too many of levels of nested children in the ScrollView for it to bubble down the drag event. For what it’s worth…