Author Topic: UIScrollView positioning child objects  (Read 3209 times)

chiblue

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 21
    • View Profile
UIScrollView positioning child objects
« on: February 18, 2014, 10:54:57 PM »
I am using UIScrollview with a clipped panel and UIGrid,  I am scrolling vertically...  I want the child objects to "spring" into place in the window panel, the window is just big enough for a single child.  The problem is when dragging the list the child can end up in any position in the window...  How do I get my child object to position exactly within the clip panel.  i.e. when I drag up or down,  I want the child object in the window to be centered... I have tried the UICenterOnClick and UICenterOnChild but both of these do not work,  the UICenterOnChild positions the child object top in the middle of the window,  the UICenterOnClick does very weird things,  it centers the child outside the parent... 

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIScrollView positioning child objects
« Reply #1 on: February 19, 2014, 12:39:08 PM »
UICenterOnChild is what should be used, yes. The key is which object you attach it to. It should be like so:

Scroll view
- Grid (UICenterOnChild)
-- Child 1  (UICenterOnClick)
-- Child 2  (UICenterOnClick)
-- Child 3  (UICenterOnClick)

Keep in mind the centering will occur on the transform.position of each child. So if your transform position happens to be the top left corner, then it will center exactly on that.

You need the transform position to be the actual center of each child.

chiblue

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 21
    • View Profile
Re: UIScrollView positioning child objects
« Reply #2 on: February 19, 2014, 07:52:38 PM »
that works, thanks, the problem I have now is the positioning of the grid when sizing the window,  I added a widget between the scroll and grid but the list can no longer be dragged, if I remove the widget then the sizing does not work...

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIScrollView positioning child objects
« Reply #3 on: February 20, 2014, 10:35:38 AM »
Sizing of what? Grid doesn't reposition anything if you resize the window. You'd need to add a custom script to determine when to reposition the grid's children based on some code of yours. Grid component positions the children once, and that's it. It's a convenience script.

chiblue

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 21
    • View Profile
Re: UIScrollView positioning child objects
« Reply #4 on: February 20, 2014, 11:32:05 AM »
When I resize the window,  in a previous post someone had the same issue,  I did as you suggested in that post and added a widget into the scroll view hierarchy,  and attached the UIgrid to that,  as far as sizing and position that worked great,  but the problem is that the scroll drag does not work when this is done....  if this worked it would be ideal..

As far as putting code on the uigrid to reposition is...  would it not be better to be able to define an anchor on the uigrid object?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIScrollView positioning child objects
« Reply #5 on: February 21, 2014, 03:33:49 PM »
There is a UIGrid improvement script linked from the Useful Stuff sticky that adds an alignment setting to it as I recall.

Also the current latest version of NGUI lets you choose each scroll view's alignment, so the widget-using approach can likely be ditched.

Now onto the drag not working -- why not? What's under the touch? There must be a collider with UIDragScrollView script for it to drag the scroll view.