Scrollview touch

Hey all, 

I have this problem,
I need a way to detect touch/tap x in scrollView, for example:

            If I scroll a bit and tap the screen, I want it to give me x I tapped in scrollView(like 900).

How do I solve this?

Hi @balsaj,

You should consider checking the view’s content position against the touch position, and doing a bit of math to get the point that was touched within the view. For example:

[lua]

local function scrollListener( event )

   if ( event.phase == “began” ) then

      --print( event.x, event.y )

      local cx, cy = event.target:getContentPosition()

      print( “X POSITION WITHIN VIEW”, -cx+event.x )

   end

end

[/lua]

Hope this helps,

Brent

Thank you! This solved my problem! :smiley:

Hi @balsaj,

You should consider checking the view’s content position against the touch position, and doing a bit of math to get the point that was touched within the view. For example:

[lua]

local function scrollListener( event )

   if ( event.phase == “began” ) then

      --print( event.x, event.y )

      local cx, cy = event.target:getContentPosition()

      print( “X POSITION WITHIN VIEW”, -cx+event.x )

   end

end

[/lua]

Hope this helps,

Brent

Thank you! This solved my problem! :smiley: