Author Topic: UIScrollView Scroll to child object  (Read 4277 times)

Brad

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
UIScrollView Scroll to child object
« on: January 06, 2015, 03:07:45 PM »
I have a container with a bunch of child objects. The container has a parent object that has an UIScrollView attached.

I am curious if there is some way to have the UIScrollView scroll to specific child object. I have tried to use the MoveRelative and MoveAbsolute and I am getting some mixed results. It looks like at first glance these seem to work, but if the object is already centered or either above or below the scroll view will move off screen. Additionally when using localPosition for the scrollview object, it didn't seem to change, yet in the editor it was clearly increasing in position.

All in all I have a UIScrollView that scrolls vertically and I am looking for a way to pass in either a child object or the position of a child object to which the UIScrollView will scroll such that the child object is the new center item.


Brad

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
Re: UIScrollView Scroll to child object
« Reply #1 on: January 07, 2015, 12:42:16 PM »
Okay so I have found a few things out. Looks like using the SpringPanel.Begin(GameObject obj, vector3 pos, float strength) produces the best results, although it takes a little tweaking so here is what I did.

For the gameobject I passed in the ScrollView, the Vector3 has the x position of the scrollview y position of the scrollview + the specific menu item's y position and 0 for the z, then strength just some value.


onealexleft

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1
    • View Profile
Re: UIScrollView Scroll to child object
« Reply #2 on: January 08, 2015, 03:56:22 AM »
Just had to do this myself and found this post:
http://www.tasharen.com/forum/index.php?topic=11403.msg53047#msg53047

Basically used the relevant snippet of code inside UICenterOnClick to get this to work perfectly.

Brad

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
Re: UIScrollView Scroll to child object
« Reply #3 on: January 08, 2015, 12:55:55 PM »
Thank you very much, yeah the code inside UICenterOnClick worked quite well. Thanks for mentioning this.