Hello there
I am trying to have my own objects inside a scrollview widget,
My objects need to have a touch event (my own custom buttons).
The problem is that when I try to scroll the view, touching the objects it always runs the event of the object.
I tried the solution that was suggested (using event.phase == “moved” ) but it never gets to that event phase. The only event.phase it runs is “began”.
How do I handle this so that when the “myOwnItem” is moved, it does not fire the touch event?
Bellow I have created a test code, simplified as much as possible in order to recreate and demonstrate the problem.
local widget = require( "widget" ) local scrollView = widget.newScrollView{ top = 5, left = 0, width = display.contentWidth, height = display.contentHeight , scrollWidth = display.contentWidth, scrollHeight = display.contentHeight, horizontalScrollDisabled = true } local function myItemTouchListener( event ) print('the event phase is ' .. event.phase) if event.phase == "moved" then local dx = math.abs( event.x - event.xStart ) local dy = math.abs( event.y - event.yStart ) -- if finger drags button more than 5 pixels, pass focus to scrollView if dx \> 5 or dy \> 5 then scrollView:takeFocus( event ) end elseif event.phase=="began" then print ('we dont want this to run EVERY time!!') end end local myOwnItem = display.newRect(2, 2, 300, 100) myOwnItem:setFillColor(255, 0, 0) scrollView:insert(myOwnItem) myOwnItem:addEventListener( "touch", myItemTouchListener )