Multitouch vs ScrollView with Button

If turn on multitouch

system.activate("multitouch"); 

in this code:

local widget = require( "widget" ) local scrollView = widget.newScrollView { top = 100, left = 10, width = 300, height = 400, scrollWidth = 600, scrollHeight = 800, horizontalScrollDisabled = true } -- The touch listener function for the button (created below) local function handleButtonEvent( event ) local phase = event.phase if ( phase == "moved" ) then local dy = math.abs( ( event.y - event.yStart ) ) -- If the touch on the button has moved more than 10 pixels, -- pass focus back to the scroll view so it can continue scrolling if ( dy \> 10 ) then scrollView:takeFocus( event ) end end return true end local button1 = widget.newButton { left = 100, top = 200, id = "button1", label = "Default", onEvent = handleButtonEvent } scrollView:insert( button1 )

than  handleButtonEvent won’t work! It’s impossible to tap button.

Be careful, guys. :slight_smile:

Hi @2reckiy,

Are you getting any response at all from the “handleButtonEvent” function? Meaning, if you put a print() statement in there, is it responding at all?

Thanks,

Brent

At first it’s works. But after scroll “handleButtonEvent” does not work anymore.

So i have switch on\off multitouch in certain cases.

I think it helps you.

Hi @2reckiy,

Speaking from a basic design perspective, what behavior is ideal for you? Should the scrollView scroll with one finger touch-drag? If so, what should happen when the user places the second touch down and drags? Should that touch “take control” of the scrollView, or should it be ignored in favor of the original (first) touch? If the user touches the scrollView, should the button be triggered by the second touch, or could the first touch trigger it?

Basically, these type of questions are common when working with multi-touch, which can be quite tricky by basic principle (simply the design considerations, before you do the coding).

It seems like you’re turning off multi-touch at some points, which I believe is the correct approach. It’s useful (and necessary) for some UI/game design, but it’s not appropriate for all scenes/screens in an app.

Take care,

Brent

Hi @2reckiy,

Are you getting any response at all from the “handleButtonEvent” function? Meaning, if you put a print() statement in there, is it responding at all?

Thanks,

Brent

At first it’s works. But after scroll “handleButtonEvent” does not work anymore.

So i have switch on\off multitouch in certain cases.

I think it helps you.

Hi @2reckiy,

Speaking from a basic design perspective, what behavior is ideal for you? Should the scrollView scroll with one finger touch-drag? If so, what should happen when the user places the second touch down and drags? Should that touch “take control” of the scrollView, or should it be ignored in favor of the original (first) touch? If the user touches the scrollView, should the button be triggered by the second touch, or could the first touch trigger it?

Basically, these type of questions are common when working with multi-touch, which can be quite tricky by basic principle (simply the design considerations, before you do the coding).

It seems like you’re turning off multi-touch at some points, which I believe is the correct approach. It’s useful (and necessary) for some UI/game design, but it’s not appropriate for all scenes/screens in an app.

Take care,

Brent