ScrollView : Y Position Currently Being Viewed

Dear Corona,

Since the tableView has issues, I am trying to implement tableView in scrollView. Everything seems to be ‘transferable’, except the ‘onRowRender’, which I am unable to get in scrollView.

The closest is ‘scrollView:getContentPosition()’, but this only tracks up to the user’s last touch. If the user scrolls fast, the ‘getContentPosition()’ does not show the ’ actual y position’ the user is viewing in scrollView.

Please advise on the best way to get the ‘actual y position’, similar to ‘onRowRender’.

Thanks

Hi @yosu,

I suppose the best way would be to access “event.target._view.y” in the scroll listener. But, be careful to check that it exists (not nil) before you try to use it, since it doesn’t get returned during the “spring back from top or bottom limit” events, at least in my testing.

Best regards,

Brent

Dear Brent,

Thanks. But the scollView listener will not give any ‘event’ when the user lifts up the finger (but the scrollView is still scrolling). So, the ‘_view.y’ is actually still giving the last location, and not the current y-location which is actually still scrolling and changing.

I think another ‘listener’ method is needed for scrollView in this case, where it constantly returns the x/y location.

thanks

Hi @yosu,

You may be able to use these parameters in the same manner, just instead of doing that inside the event listener, do it in a Runtime listener. In my example where I stated “event.target._view.y”, “event.target” is just the widget itself… so in theory (although I haven’t tested it), you can just do something like “myWidget._view.y” in a Runtime listener.

Brent

Thanks brent. It works! But using the runtime listener with ‘enterFrame’ looks a bit heavy.

For those who are interested, this is what I did :

-- Create your scrollView widget here first local scrollView = .... -- This will be called on every frame (either 30 or 60, depending on your setting). See http://www.coronalabs.com/blog/2012/02/21/understanding-coronas-enterframe-event/ local function onFrame(event) print( "scrollView.\_view.y : " , scrollView.\_view.y ) print( "scrollView.\_view.x : " , scrollView.\_view.x ) end Runtime:addEventListener( "enterFrame", onFrame )

Hi @yosu,

I suppose the best way would be to access “event.target._view.y” in the scroll listener. But, be careful to check that it exists (not nil) before you try to use it, since it doesn’t get returned during the “spring back from top or bottom limit” events, at least in my testing.

Best regards,

Brent

Dear Brent,

Thanks. But the scollView listener will not give any ‘event’ when the user lifts up the finger (but the scrollView is still scrolling). So, the ‘_view.y’ is actually still giving the last location, and not the current y-location which is actually still scrolling and changing.

I think another ‘listener’ method is needed for scrollView in this case, where it constantly returns the x/y location.

thanks

Hi @yosu,

You may be able to use these parameters in the same manner, just instead of doing that inside the event listener, do it in a Runtime listener. In my example where I stated “event.target._view.y”, “event.target” is just the widget itself… so in theory (although I haven’t tested it), you can just do something like “myWidget._view.y” in a Runtime listener.

Brent

Thanks brent. It works! But using the runtime listener with ‘enterFrame’ looks a bit heavy.

For those who are interested, this is what I did :

-- Create your scrollView widget here first local scrollView = .... -- This will be called on every frame (either 30 or 60, depending on your setting). See http://www.coronalabs.com/blog/2012/02/21/understanding-coronas-enterframe-event/ local function onFrame(event) print( "scrollView.\_view.y : " , scrollView.\_view.y ) print( "scrollView.\_view.x : " , scrollView.\_view.x ) end Runtime:addEventListener( "enterFrame", onFrame )