A Problem of ScrollView

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
end

local 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

I’m not fully sure I understand what the problem is and what question you’re asking.  Can you try to explain it a little better?

Thanks

Rob

As my code, I make 100 rectangles in the scrollview, when I scroll up/down the rectangle object that the scrollview has common three phases began, moved and ended.

After scrolling the rectangle object, and the phase is ended, at the same time, the rectangle object would scroll a little while to the stoppped phase or limitedReach.

I want to know the change of y value at this period( between ended phase and stopped phase )

I don’t know is this explaintion more better than before, I have do my better to explain.

Why do you want to stop the scrolling? Are you wanting to scroll to a specific spot?

If you don’t want the bouncing you can turn that off:  https://docs.coronalabs.com/api/library/widget/newScrollView.html#isbounceenabled-optional

Rob

https://youtu.be/CK9e-41jgvw

This vedio is a demo about the problem that I want to express.

The first 10 seconds is the function what I want to do.

[white title would appear/disappear according to the y value by getContentPosition()]

The last 5 seconds is when flicking the scrollview, the function would be working incorrect.

I copied your code to a new main.lua and created a config.lua and I see the behavior you want. I also don’t get the white box. It would be best for you to put your test project in a .zip file and share it with the community by putting a link to the .zip file on Dropbox, Google Drive, etc.

Rob

https://drive.google.com/open?id=1g-R2UmyH3xHylA8MNk4WwUS7y8kfA0Xq

This link is the scrollview project zip file

I guessed at what you wanted:

https://github.com/roaminggamer/RG_FreeStuff/raw/master/AskEd/2018/04/scrollviewGuess.zip

https://www.youtube.com/watch?v=78EPp1FRh7U&feature=youtu.be

Yes, this is what I want and thanks for your help

I’m not fully sure I understand what the problem is and what question you’re asking.  Can you try to explain it a little better?

Thanks

Rob

As my code, I make 100 rectangles in the scrollview, when I scroll up/down the rectangle object that the scrollview has common three phases began, moved and ended.

After scrolling the rectangle object, and the phase is ended, at the same time, the rectangle object would scroll a little while to the stoppped phase or limitedReach.

I want to know the change of y value at this period( between ended phase and stopped phase )

I don’t know is this explaintion more better than before, I have do my better to explain.

Why do you want to stop the scrolling? Are you wanting to scroll to a specific spot?

If you don’t want the bouncing you can turn that off:  https://docs.coronalabs.com/api/library/widget/newScrollView.html#isbounceenabled-optional

Rob

https://youtu.be/CK9e-41jgvw

This vedio is a demo about the problem that I want to express.

The first 10 seconds is the function what I want to do.

[white title would appear/disappear according to the y value by getContentPosition()]

The last 5 seconds is when flicking the scrollview, the function would be working incorrect.

I copied your code to a new main.lua and created a config.lua and I see the behavior you want. I also don’t get the white box. It would be best for you to put your test project in a .zip file and share it with the community by putting a link to the .zip file on Dropbox, Google Drive, etc.

Rob

https://drive.google.com/open?id=1g-R2UmyH3xHylA8MNk4WwUS7y8kfA0Xq

This link is the scrollview project zip file

I guessed at what you wanted:

https://github.com/roaminggamer/RG_FreeStuff/raw/master/AskEd/2018/04/scrollviewGuess.zip

https://www.youtube.com/watch?v=78EPp1FRh7U&feature=youtu.be

Yes, this is what I want and thanks for your help