I’m trying to have a “tapable” object in a scrollview that “do something” when its tapped, but if it’s touched, held and moved the scrollView instead should scroll.
The below is a simplified code snippet showing the two objects in question:
local widget = require("widget") local w = display.contentWidth local h = display.contentHeight local rectTouch = function(e) if (e.phase == "ended") then e.target:setFillColor(1,0,0) end return true -- touch handled end local topScrollView = widget.newScrollView { left = 0, top = 0, width = w, height = h/6, scrollWidth = w\*4, horizontalScrollDisabled = false, verticalScrollDisabled = true, backgroundColor = {0.25,0.3,0.35} } local rect = display.newRect(w/2, h/12, h/12, h/12) rect:addEventListener( "touch", rectTouch ) topScrollView:insert(rect)
I’ve tried letting the rect object handle all the touch input and hard-setting the scroll value of the scrollview (based on the number of pixels moved (e.startX - e.x type)), but the scroll movement just becomes jerky. There must be a better way?