Author Topic: Is there a way to know which cell number a Scroll View is currently centered on?  (Read 5866 times)

alexh0101

  • Newbie
  • *
  • Thank You
  • -Given: 4
  • -Receive: 0
  • Posts: 30
    • View Profile
If my scroll view has a grid of say 10 items, is there a way of knowing the the scroll view is currently centred on the nth item of the grid?

Also is there a callback function in NGUI when CenterOnChild has been executed, or do I have to do that manually?
« Last Edit: April 05, 2015, 09:55:41 AM by alexh0101 »

devomage

  • Sr. Member
  • ****
  • Thank You
  • -Given: 7
  • -Receive: 67
  • Posts: 250
    • View Profile
wish there was a ScrollTo(rownumber)

quite often the row i'd like displayed is buried deep in the scrollview.

didnt mean to hijack the thread, but it reminded me of a mod i did to solve the above...

i ended up having a fixed position and smoothly scrolling until the desired item is locked to that position.  fixed positions being the top, center and bottom of the scrollview.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
UICenterOnChild.centeredObject tells you what it's centered over. If you aren't using UICenterOnChild, then you need to do math. Knowing UIPanel's worldCorners, use (corners[0] + corners[2]) * 0.5 to calculate the center. Now with the center in hand, run through your grid's children and figure out which one is the closest to that point.

To go to a specific child, use UICenterOnChild.CenterOn, or if you don't use it -- SpringPanel.Begin.