Hi everyone
I have a problem of scrollview.
When I flick/swipe the rectangle object after ended phase, the rectangle object is still scrolling until stopped phase or limitreached.
How to know the y value between ended phase and stopped phase or limitreached when object scrolling
display.setDefault( “background”, 245/255, 245/255, 245/255)
local widget = require(“widget”)
local screenW, screenH = display.contentWidth, display.contentHeight
local cx, cy = display.contentCenterX, display.contentCenterY
local ox, oy = math.abs(display.screenOriginX), math.abs(display.screenOriginY)local title
local function scrollViewListener( event )
local phase = event.phase
local x,y = event.target:getContentPosition()
if ( phase == “began” ) then
print(phase)
print("y: "…y)
elseif ( phase == “moved”) then
if (y > -90) then
title:setFillColor( 1, 1, 1, 0)
end
if (y <= -90) then
title:setFillColor( 1, 1, 1, 0.2)
end
if (y < -95) then
title:setFillColor( 1, 1, 1, 0.3)
end
if (y < -100) then
title:setFillColor( 1, 1, 1, 0.4)
end
if (y < -105) then
title:setFillColor( 1, 1, 1, 0.5)
end
if (y < -110) then
title:setFillColor( 1, 1, 1, 0.6)
end
if (y < -115) then
title:setFillColor( 1, 1, 1, 0.8)
end
if (y < -120) then
title:setFillColor( 1, 1, 1, 1)
end
elseif ( phase == “ended”) then
print(phase)
print("y: "…y)
elseif ( phase == “stopped”) then
print(phase)
print("y: "…y)
end
return true
endlocal scrollView = widget.newScrollView({
x = cx,
y = cy,
width = screenW,
height = screenH+oy+oy,
isBounceEnabled = false,
horizontalScrollDisabled = true,
backgroundColor = { 1, 0, 0, 0.3},
listener = scrollViewListener
})
local scrollGroup = display.newGroup()
scrollView:insert(scrollGroup)title = display.newRect( cx, -oy, screenW+ox+ox, screenH*0.2)
title:setFillColor( 1, 1, 1, 0)local baseX = scrollView.contentWidth*0.5
local baseWidth = scrollView.contentWidth*0.7
local baseHeight = 100
local scrollHeight = 0
local maxRectNum = 100
for i = 1, maxRectNum do
local base = display.newRect( scrollGroup, baseX, (10+baseHeight*0.5)+(10+baseHeight)*(i-1), baseWidth, baseHeight)
base:setFillColor( math.random(), math.random(), math.random())
base:addEventListener(“touch”,
function ( event )
local phase = event.phase
if ( phase == “moved” ) then
scrollView:takeFocus(event)
end
return true
end)
if ( i == maxRectNum ) then
scrollHeight = base.y+baseHeight*0.5+10
scrollView:setScrollHeight(scrollHeight)
end
end