Getting The Current Position Of A Scrollview

Is there a method to get the current scroll position x/y?

[lua]

        scroller = widget.newScrollView{
            width                = display.viewableContentWidth,
            height              = display.viewableContentHeight,
            scrollWidth      = 700,
            scrollHeight     = 1000,
            hideScrollBar  = true,
            friction              = 0.75,
            listener             = update
        }

    local function update( event )       
        if “ended” == event.phase then
            --print( scroller:getScrollPosition() )
        end
    end

[/lua]

I am trying to get the position at the end phase so I can run functions based on those coordinates.

If I remember rightly it would be:

[lua]

scroller.content.x

scroller.content.y

[/lua]

Might be wrong though!

I tried that and received the error:

Runtime error attempt to index fie ld ‘content’ (a nil value)
 

I played around some more and was able to get the values by adjusting my original code.

[lua]

local xView, yView = scroller:getContentPosition()
            print("X: " … (xView))
            print("Y: " … (yView))

[/lua]

xView and yView were functions and threw the concat error. Wrapping them in parenthesis allowed them to execute first and return a value.

Hope that helps someone if they run across the same issue. :slight_smile:

If I remember rightly it would be:

[lua]

scroller.content.x

scroller.content.y

[/lua]

Might be wrong though!

I tried that and received the error:

Runtime error attempt to index fie ld ‘content’ (a nil value)
 

I played around some more and was able to get the values by adjusting my original code.

[lua]

local xView, yView = scroller:getContentPosition()
            print("X: " … (xView))
            print("Y: " … (yView))

[/lua]

xView and yView were functions and threw the concat error. Wrapping them in parenthesis allowed them to execute first and return a value.

Hope that helps someone if they run across the same issue. :slight_smile: