Touch Scrollview event in Corona SDK?

I have a scrollview widget with one child (myrect)

I want to detect a touch-close event for "myrect", however at the moment it only detects the "initial" phase !!

here is the full code

 --main.lua
 local widget = require "widget"

 local myscrollview = widget.newScrollView{}

 local myrect = display.newRect(0, 0, display.contentWidth, 68)                  
 myrect:setFillColor(255,100,100,255)
 myscrollview:insert(myrect)

 local function ontouch(event)

    if event.phase == "ended" then
            print("event ended")
    end
end
myrect:addEventListener( "touch", ontouch )

I need basic functionality, it’s strange that the crown doesn’t support this, or maybe I’m missing something

Many thanks

+3
source share
2 answers

Thanks, SatheeshJM is your code for some how to give me the wrong result, so when I click anywhere outside the rect, the touch end event will fire

but finally i have a solution. Just in case, if anyone is interested.

here is an extended version of the solution

Danny http://developer.anscamobile.com/forum/2012/05/15/scrollview-problem

https://gist.github.com/1590908

local widget = require "widget"

local myscrollview = widget.newScrollView{}

local myrect = display.newRect(0, 0, display.contentWidth, 68)                  
myrect:setFillColor(255,100,100,255)
myscrollview:insert(myrect)

local function ontouch(event)

    if event.phase == "moved" then
        local dx = math.abs( event.x - event.xStart )
        local dy = math.abs( event.y - event.yStart )

        if dx > 5 or dy > 5 then
            myscrollview:takeFocus( event )
        end
    elseif event.phase == "ended" then
    display.getCurrentStage():setFocus(nil)
            print("event ended")
    end

    return true
end
myrect:addEventListener( "touch", ontouch )
+4

, "".

scrollview scrollview, scrollview. , scrollview "" "" "" . .

"",

 local function ontouch(event)
        if event.phase == "began" then 
            return true
        elseif event.phase == "ended" then
            print("event ended")
        end
  end

. , , . , .

, !

EDIT:

, ! , scrollview.

 --main.lua
 local widget = require "widget"
 local myrect

 local function scrollviewListener(event)
    display.getCurrentStage():setFocus(myrect)
 end 
 local myscrollview = widget.newScrollView{listener = scrollviewListener}


 myrect = display.newRect(0, 0, display.contentWidth, 68)                  
 myrect:setFillColor(255,100,100,255)
 myscrollview:insert(myrect)


 local function ontouch(event)

    if event.phase == "ended" then
            print("event ended")
    end
end
myrect:addEventListener( "touch", ontouch )
+2

All Articles