Author Topic: ScrolloView scroll automatically to last children, please  (Read 4145 times)

FOX_ITA

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
ScrolloView scroll automatically to last children, please
« on: February 03, 2014, 11:38:02 AM »
Hello guys,

im having some troubles how the scrollview works and how to get my things works.

the scripts above :

  1. GameObject profile = NGUITools.AddChild(m_profilesGrid.gameObject, prefabPlayerProfile);
  2.                 UIButton button = profile.GetComponentInChildren<UIButton>();
  3.                 UIEventListener.Get(button.gameObject).onClick += this.OnPlayerSelection;
  4.                 m_profilesGrid.repositionNow = true;
  5.  
  6.                 UILabel profileLabel = profile.GetComponentInChildren<UILabel>();
  7.                 Debugger.Assert(profileLabel != null);
  8.  
  9.                 profileLabel.text = Game.State.GetProfile(profileIndex).Name;
  10.  
  11.                 UIPanel mPanel;
  12.                 UICenterOnChild mCenter;
  13.                
  14.  
  15.                 mCenter = NGUITools.FindInParents<UICenterOnChild>(profile.gameObject);
  16.                 mPanel = NGUITools.FindInParents<UIPanel>(profile.gameObject);
  17.  
  18.                 mCenter.CenterOn(profile.transform);
  19.                 SpringPanel.Begin(mPanel.cachedGameObject, mPanel.cachedTransform.InverseTransformPoint(profile.transform.position), 6f);
  20.  

The child is added correctly in row but if i move the slider to last one or another position, all the time brings me to the first.

Instead of this behaviour i'd like to move to the last one added.

Can you help me please?

many thanks!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: ScrolloView scroll automatically to last children, please
« Reply #1 on: February 04, 2014, 02:29:25 AM »
I don't quite understand what you're trying to do. If it's just center on a specific object, UICenterOnChild.CenterOn is enough. Why are you doing a SpringPanel as well? When you use a scroll bar and release it, UICenterOnChild kicks in, and it won't run your custom code.

FOX_ITA

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
Re: ScrolloView scroll automatically to last children, please
« Reply #2 on: February 05, 2014, 08:22:25 AM »
Hi,

thanks to reply. I just wanna center on the last child. Now i'm only using UICenterOnChild.CenterOn using the last object ( profile ) but all the time is centered on the first child..!

i removed the SpringPanel...

thanks

EDIT : i've fixed. Was simple. I just wanna center instantly after the item creation, but i understood that the place of creation was under the first item and then moved. So i delayed the OnCenter call and everything work now!!
« Last Edit: February 05, 2014, 12:28:16 PM by FOX_ITA »