Scrollview: :getContentPosition() on limit return never the same mesure

Hi every one.

How is possible that if I arrive at the limit of the scrollview and I cast the scrollView:getContentPosition() 

return me every time a different result? (there is a variation of 40-50 px!)

In this image I printed the return of the function in the same scrollview!

Hi @robertominghi,

Have you enabled the “bounce” effect, which is true by default? Meaning, when you reach the limit, is there the “elastic” resistance where the contents resist and then snap back? If so, this would explain why you’re getting various results… the limit is technically reached, but the contents are still moving slightly as the control resists.

Best regards,

Brent

Hi

thank you for your reply. The “bounce” effect is not enabled is for that I think is really rare this beahviour. 

Regards,

Roberto

Hi Roberto,

Please post your code, including:

  1. Where you set up the widget and insert content into it.

  2. The listener function which is producing the print results you showed before.

Also, please surround the code in lua tags for clarity:

[lua] [/lua]

Thanks,

Brent

Hi Brent,

I post all the code that talk about the scrollviews:

----------------------------------------------------------------------------------------- -- -- menu.lua - requires -- ---------------------------------------------------------------------------------------- -- all Requires ------------------------------------------------------------------------------------------- -- IMPOSTAZIONI PRELIMINARI ------------------------------------------------------------------------------------------- some impostation (like set font for charcter) ------------------------------------------------------------------------------------------- -- -- VARIABILI GLOBALI -- ------------------------------------------------------------------------------------------- -- all variables local scrollview, Oscrollview local OSVW = display.contentWidth - L6X local SVH = display.contentHeight \* 0.85 night = 10 local horizusedspace = WL \* night local vertusedspace = YG + (HL \* #allplayer) local Hsv,Vsv = 0,0 local roba = 0 ------------------------------------------------------------------------------------------- -- -- FUNZIONI DI GESTIONE -- ------------------------------------------------------------------------------------------- local function scrollListener(event) local phase = event.phase if ( phase == "began" ) then -- print (OscrollView:getContentPosition().x) roba, Vsv = scrollView:getContentPosition() -- print ("Hsv = " .. Hsv .. " Vsv = " .. Vsv) elseif ( phase == "moved" ) then -- print( "Scroll view was moved element prova = " .. prova.x .. " " .. prova.y ) elseif ( phase == "ended" ) then roba, Vsv = scrollView:getContentPosition() -- print ("Hsv = " .. Hsv .. " Vsv = " .. Vsv) end if ( event.limitReached ) then if ( event.direction == "up" ) then print( "Reached top limit" ) -- print (vertusedspace) if vertusedspace \> SVH then Vsv = SVH - vertusedspace + (HL / 2) else Vsv = 0 end elseif ( event.direction == "down" ) then print( "Reached down limit" ) Vsv = 0 end else end return true end local function scrollListener2(event) local phase = event.phase if ( phase == "began" ) then -- print (OscrollView:getContentPosition().x) Hsv, roba = OscrollView:getContentPosition() -- print ("Hsv = " .. Hsv .. " Vsv = " .. Vsv) for i=1, night do prova[i].isVisible = true prova[i].x = prova[i].x - L6X - Hsv prova[i].y = prova[i].y + WL + Vsv OscrollView:insert( prova[i] ) if prova[i].y \< L3Y then prova[i].isVisible = false elseif prova[i].y \> L3Y then prova[i].isVisible = true end end elseif ( phase == "moved" ) then -- print( "Scroll view was moved element prova = " .. prova.x .. " " .. prova.y ) elseif ( phase == "ended" ) then Hsv,roba = OscrollView:getContentPosition() -- print ("Hsv = " .. Hsv .. " Vsv = " .. Vsv) for i=1, night do prova[i].x = prova[i].x + L6X + Hsv -- print ("prova["..i.."].x = " .. prova[i].x ) prova[i].y = prova[i].y - WL - Vsv if prova[i].x \< L6X then prova[i].isVisible = false elseif prova[i].x \> L6X then prova[i].isVisible = true end scrollView:insert( prova[i] ) -- print (Hsv .. " ------2") end -- print( "Scroll view was released" ) end if ( event.limitReached ) then if ( event.direction == "left" ) then print( "Reached left limit" ) print (OscrollView:getContentPosition()) print (horizusedspace) print (OSVW) if horizusedspace \> OSVW then Hsv = horizusedspace + (WL \* 2) print ("Hsv = " .. Hsv) else Hsv = 0 print (Hsv .. " ------1") end for i=1, night do prova[i].x = L6X + display.contentWidth \* (0.05 + (0.1 \* (i - 1))) - Hsv --prova[i].isVisible = true if prova[i].x \< L6X then prova[i].isVisible = false elseif prova[i].x \> L6X then prova[i].isVisible = true end end elseif ( event.direction == "right" ) then print( "Reached right limit" ) Hsv = 0 -- print (Hsv .. " ------1") for i=1, night do prova[i].x = L6X + display.contentWidth \* (0.05 + (0.1 \* (i - 1))) prova[i].isVisible = true end end end return true end ----------------------------------------------------------------------------------------- -- BEGINNING OF YOUR IMPLEMENTATION -- -- NOTE: Code outside of listener functions (below) will only be executed once, -- unless storyboard.removeScene() is called. -- ----------------------------------------------------------------------------------------- -- Called when the scene's view does not exist: function scene:createScene( event ) group = self.view var = event.params.var background = -- background -------------------------------------------------------------------------------------------- -- DATI -------------------------------------------------------------------------------------------- scrollView = widget.newScrollView { top = display.contentHeight\* 0.08, left = 0, width = display.contentWidth, height = SVH, scrollWidth = 0, scrollHeight = 0, hideBackground = true, listener = scrollListener, topPadding = 0, bottomPadding = 0, horizontalScrollDisabled = true, isBounceEnabled=false } for i=1, #allplayer do --other dates, not important for my questions end -- night = 10 -- In caso che non siamo alla prima notte si scrolla in orizontale le colonne delle votazioni if night \> 0 then OscrollView = widget.newScrollView { top = 0, left = L6X, width = OSVW, height = display.contentHeight \* 0.925, scrollWidth = horizusedspace, scrollHeight = 0, hideBackground = true, listener = scrollListener2, leftPadding = 0, rightPadding = 0, horizontalScrollDisabled = false, verticalScrollDisabled = true, isBounceEnabled=false } for j=1, night do local varoptnotte = { text = j, x = display.contentWidth \* (0.05 + (0.1 \* (j-1))), y = YG, width = WVOT, font = namefont, fontSize = FS, align = "center" } notti[j] = display.newText( varoptnotte ) notti[j]:setFillColor( 0 ) lv[j] = display.newLine( display.contentWidth \* (0.1 + (0.1 \* (j-1))) , 0, display.contentWidth \* (0.1 + (0.1 \* (j-1))) , display.contentHeight \* 1.2) lv[j]:setStrokeColor( 0, 0, 0, 1) lv[j].strokeWidth = 1 end end local j = 1 for i=1, night do local varoptm = { text = "X"..i, x = L6X + display.contentWidth \* (0.05 + (0.1 \* (i - 1))), y = YG + (HL \* (j - 1)), width = 25, font = namefont, fontSize = FS, align = "center" } prova[i] = display.newText( varoptm ) prova[i]:setFillColor( 0 ) j = j+1 if j \> #allplayer then j= 1 end end ------- POSSIBILE SOLUZIONE SCROLLTOPOSITION???? -------------------- group:insert( background ) if n ~= {} then for i=1, #n do -- print(n[i]) scrollView:insert( y[i] ) scrollView:insert( n[i] ) scrollView:insert( r[i] ) scrollView:insert( xa[i] ) scrollView:insert( xm[i] ) scrollView:insert( iconAMAT[i] ) scrollView:insert( iconCONT[i] ) scrollView:insert( iconCRIM[i] ) scrollView:insert( iconMALE[i] ) scrollView:insert( iconNEGR[i] ) scrollView:insert( iconNOSF[i] ) scrollView:insert( iconROME[i] ) scrollView:insert( iconVAMP[i] ) scrollView:insert( l[i] ) end for i=1, night do scrollView:insert( prova[i] ) end end if notti ~= {} then for i=1, #notti do OscrollView:insert( notti[i] ) OscrollView:insert( lv[i] ) end end if scrollView ~= nil then group:insert( scrollView ) end if OscrollView ~= nil then group:insert( OscrollView ) end end -- Called immediately after scene has moved onscreen: function scene:enterScene( event ) group = self.view end -- Called when scene is about to move offscreen: function scene:exitScene( event ) group = self.view if scrollView then scrollView:removeSelf( ) scrollView = nil end end -- If scene's view is removed, scene:destroyScene() will be called just prior to: function scene:destroyScene( event ) group = self.view if nextBtn then nextBtn:removeSelf() -- widgets must be manually removed nextBtn = nil end end ----------------------------------------------------------------------------------------- -- END OF YOUR IMPLEMENTATION ----------------------------------------------------------------------------------------- -- "createScene" event is dispatched if scene's view does not exist scene:addEventListener( "createScene", scene ) -- "enterScene" event is dispatched whenever scene transition has finished scene:addEventListener( "enterScene", scene ) -- "exitScene" event is dispatched whenever before next scene's transition begins scene:addEventListener( "exitScene", scene ) -- "destroyScene" event is dispatched before view is unloaded, which can be -- automatically unloaded in low memory situations, or explicitly via a call to -- storyboard.purgeScene() or storyboard.removeScene(). scene:addEventListener( "destroyScene", scene ) ----------------------------------------------------------------------------------------- return scene

Here you are

Hi @robertominghi,

Sorry about the previous post (now deleted). I responded to the wrong post. :slight_smile: I will respond to you in a moment…

Brent

Hi @robertominghi,

I did some quick testing and I think this is a bug. I’ve reported it to the engineers. Thanks for bringing it to my attention.

Brent

Hi Brent,

I’m glad that is a bug and not a problem of my code :slight_smile: Let me know when you had fix the bug. And if you need I’m at yours disposition.

Regards,

Roberto

Hi @robertominghi,

Have you enabled the “bounce” effect, which is true by default? Meaning, when you reach the limit, is there the “elastic” resistance where the contents resist and then snap back? If so, this would explain why you’re getting various results… the limit is technically reached, but the contents are still moving slightly as the control resists.

Best regards,

Brent

Hi

thank you for your reply. The “bounce” effect is not enabled is for that I think is really rare this beahviour. 

Regards,

Roberto

Hi Roberto,

Please post your code, including:

  1. Where you set up the widget and insert content into it.

  2. The listener function which is producing the print results you showed before.

Also, please surround the code in lua tags for clarity:

[lua] [/lua]

Thanks,

Brent

Hi Brent,

I post all the code that talk about the scrollviews:

----------------------------------------------------------------------------------------- -- -- menu.lua - requires -- ---------------------------------------------------------------------------------------- -- all Requires ------------------------------------------------------------------------------------------- -- IMPOSTAZIONI PRELIMINARI ------------------------------------------------------------------------------------------- some impostation (like set font for charcter) ------------------------------------------------------------------------------------------- -- -- VARIABILI GLOBALI -- ------------------------------------------------------------------------------------------- -- all variables local scrollview, Oscrollview local OSVW = display.contentWidth - L6X local SVH = display.contentHeight \* 0.85 night = 10 local horizusedspace = WL \* night local vertusedspace = YG + (HL \* #allplayer) local Hsv,Vsv = 0,0 local roba = 0 ------------------------------------------------------------------------------------------- -- -- FUNZIONI DI GESTIONE -- ------------------------------------------------------------------------------------------- local function scrollListener(event) local phase = event.phase if ( phase == "began" ) then -- print (OscrollView:getContentPosition().x) roba, Vsv = scrollView:getContentPosition() -- print ("Hsv = " .. Hsv .. " Vsv = " .. Vsv) elseif ( phase == "moved" ) then -- print( "Scroll view was moved element prova = " .. prova.x .. " " .. prova.y ) elseif ( phase == "ended" ) then roba, Vsv = scrollView:getContentPosition() -- print ("Hsv = " .. Hsv .. " Vsv = " .. Vsv) end if ( event.limitReached ) then if ( event.direction == "up" ) then print( "Reached top limit" ) -- print (vertusedspace) if vertusedspace \> SVH then Vsv = SVH - vertusedspace + (HL / 2) else Vsv = 0 end elseif ( event.direction == "down" ) then print( "Reached down limit" ) Vsv = 0 end else end return true end local function scrollListener2(event) local phase = event.phase if ( phase == "began" ) then -- print (OscrollView:getContentPosition().x) Hsv, roba = OscrollView:getContentPosition() -- print ("Hsv = " .. Hsv .. " Vsv = " .. Vsv) for i=1, night do prova[i].isVisible = true prova[i].x = prova[i].x - L6X - Hsv prova[i].y = prova[i].y + WL + Vsv OscrollView:insert( prova[i] ) if prova[i].y \< L3Y then prova[i].isVisible = false elseif prova[i].y \> L3Y then prova[i].isVisible = true end end elseif ( phase == "moved" ) then -- print( "Scroll view was moved element prova = " .. prova.x .. " " .. prova.y ) elseif ( phase == "ended" ) then Hsv,roba = OscrollView:getContentPosition() -- print ("Hsv = " .. Hsv .. " Vsv = " .. Vsv) for i=1, night do prova[i].x = prova[i].x + L6X + Hsv -- print ("prova["..i.."].x = " .. prova[i].x ) prova[i].y = prova[i].y - WL - Vsv if prova[i].x \< L6X then prova[i].isVisible = false elseif prova[i].x \> L6X then prova[i].isVisible = true end scrollView:insert( prova[i] ) -- print (Hsv .. " ------2") end -- print( "Scroll view was released" ) end if ( event.limitReached ) then if ( event.direction == "left" ) then print( "Reached left limit" ) print (OscrollView:getContentPosition()) print (horizusedspace) print (OSVW) if horizusedspace \> OSVW then Hsv = horizusedspace + (WL \* 2) print ("Hsv = " .. Hsv) else Hsv = 0 print (Hsv .. " ------1") end for i=1, night do prova[i].x = L6X + display.contentWidth \* (0.05 + (0.1 \* (i - 1))) - Hsv --prova[i].isVisible = true if prova[i].x \< L6X then prova[i].isVisible = false elseif prova[i].x \> L6X then prova[i].isVisible = true end end elseif ( event.direction == "right" ) then print( "Reached right limit" ) Hsv = 0 -- print (Hsv .. " ------1") for i=1, night do prova[i].x = L6X + display.contentWidth \* (0.05 + (0.1 \* (i - 1))) prova[i].isVisible = true end end end return true end ----------------------------------------------------------------------------------------- -- BEGINNING OF YOUR IMPLEMENTATION -- -- NOTE: Code outside of listener functions (below) will only be executed once, -- unless storyboard.removeScene() is called. -- ----------------------------------------------------------------------------------------- -- Called when the scene's view does not exist: function scene:createScene( event ) group = self.view var = event.params.var background = -- background -------------------------------------------------------------------------------------------- -- DATI -------------------------------------------------------------------------------------------- scrollView = widget.newScrollView { top = display.contentHeight\* 0.08, left = 0, width = display.contentWidth, height = SVH, scrollWidth = 0, scrollHeight = 0, hideBackground = true, listener = scrollListener, topPadding = 0, bottomPadding = 0, horizontalScrollDisabled = true, isBounceEnabled=false } for i=1, #allplayer do --other dates, not important for my questions end -- night = 10 -- In caso che non siamo alla prima notte si scrolla in orizontale le colonne delle votazioni if night \> 0 then OscrollView = widget.newScrollView { top = 0, left = L6X, width = OSVW, height = display.contentHeight \* 0.925, scrollWidth = horizusedspace, scrollHeight = 0, hideBackground = true, listener = scrollListener2, leftPadding = 0, rightPadding = 0, horizontalScrollDisabled = false, verticalScrollDisabled = true, isBounceEnabled=false } for j=1, night do local varoptnotte = { text = j, x = display.contentWidth \* (0.05 + (0.1 \* (j-1))), y = YG, width = WVOT, font = namefont, fontSize = FS, align = "center" } notti[j] = display.newText( varoptnotte ) notti[j]:setFillColor( 0 ) lv[j] = display.newLine( display.contentWidth \* (0.1 + (0.1 \* (j-1))) , 0, display.contentWidth \* (0.1 + (0.1 \* (j-1))) , display.contentHeight \* 1.2) lv[j]:setStrokeColor( 0, 0, 0, 1) lv[j].strokeWidth = 1 end end local j = 1 for i=1, night do local varoptm = { text = "X"..i, x = L6X + display.contentWidth \* (0.05 + (0.1 \* (i - 1))), y = YG + (HL \* (j - 1)), width = 25, font = namefont, fontSize = FS, align = "center" } prova[i] = display.newText( varoptm ) prova[i]:setFillColor( 0 ) j = j+1 if j \> #allplayer then j= 1 end end ------- POSSIBILE SOLUZIONE SCROLLTOPOSITION???? -------------------- group:insert( background ) if n ~= {} then for i=1, #n do -- print(n[i]) scrollView:insert( y[i] ) scrollView:insert( n[i] ) scrollView:insert( r[i] ) scrollView:insert( xa[i] ) scrollView:insert( xm[i] ) scrollView:insert( iconAMAT[i] ) scrollView:insert( iconCONT[i] ) scrollView:insert( iconCRIM[i] ) scrollView:insert( iconMALE[i] ) scrollView:insert( iconNEGR[i] ) scrollView:insert( iconNOSF[i] ) scrollView:insert( iconROME[i] ) scrollView:insert( iconVAMP[i] ) scrollView:insert( l[i] ) end for i=1, night do scrollView:insert( prova[i] ) end end if notti ~= {} then for i=1, #notti do OscrollView:insert( notti[i] ) OscrollView:insert( lv[i] ) end end if scrollView ~= nil then group:insert( scrollView ) end if OscrollView ~= nil then group:insert( OscrollView ) end end -- Called immediately after scene has moved onscreen: function scene:enterScene( event ) group = self.view end -- Called when scene is about to move offscreen: function scene:exitScene( event ) group = self.view if scrollView then scrollView:removeSelf( ) scrollView = nil end end -- If scene's view is removed, scene:destroyScene() will be called just prior to: function scene:destroyScene( event ) group = self.view if nextBtn then nextBtn:removeSelf() -- widgets must be manually removed nextBtn = nil end end ----------------------------------------------------------------------------------------- -- END OF YOUR IMPLEMENTATION ----------------------------------------------------------------------------------------- -- "createScene" event is dispatched if scene's view does not exist scene:addEventListener( "createScene", scene ) -- "enterScene" event is dispatched whenever scene transition has finished scene:addEventListener( "enterScene", scene ) -- "exitScene" event is dispatched whenever before next scene's transition begins scene:addEventListener( "exitScene", scene ) -- "destroyScene" event is dispatched before view is unloaded, which can be -- automatically unloaded in low memory situations, or explicitly via a call to -- storyboard.purgeScene() or storyboard.removeScene(). scene:addEventListener( "destroyScene", scene ) ----------------------------------------------------------------------------------------- return scene

Here you are

Hi @robertominghi,

Sorry about the previous post (now deleted). I responded to the wrong post. :slight_smile: I will respond to you in a moment…

Brent

Hi @robertominghi,

I did some quick testing and I think this is a bug. I’ve reported it to the engineers. Thanks for bringing it to my attention.

Brent

Hi Brent,

I’m glad that is a bug and not a problem of my code :slight_smile: Let me know when you had fix the bug. And if you need I’m at yours disposition.

Regards,

Roberto