Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: erre on November 02, 2017, 05:11:19 AM

Title: Set UI Scroll View position
Post by: erre on November 02, 2017, 05:11:19 AM
Hi,

I need to pre-set the UIScrollView position on a certain position without any scrolling animation. I've found this old post:

http://www.tasharen.com/forum/index.php?topic=14130.msg62910#msg62910

Here you recommend to have a look at UICenterOnChild script and see what it does. And that's ok. I've already use that when I needed to automatically scroll a list to a given position.
This time, however, I don't want any animation. Is it possible to do that without a custom script but interacting with yours?

Thank you.

Best regards,
Andrea
Title: Re: Set UI Scroll View position
Post by: ArenMook on November 06, 2017, 07:24:41 AM
If you look at UICenterOnChild, line 252:
  1. #if UNITY_EDITOR
  2.                         if (!Application.isPlaying)
  3.                         {
  4.                                 panelTrans.localPosition = panelTrans.localPosition - localOffset;
  5.  
  6.                                 Vector4 co = mScrollView.panel.clipOffset;
  7.                                 co.x += localOffset.x;
  8.                                 co.y += localOffset.y;
  9.                                 mScrollView.panel.clipOffset = co;
  10.                         }
  11.                         else
  12. #endif
  13.                         {
  14.                                 SpringPanel.Begin(mScrollView.panel.cachedGameObject,
  15.                                         panelTrans.localPosition - localOffset, springStrength).onFinished = onFinished;
  16.                         }
Note how on top it does it immediately, while at the bottom it does it smoothly.

Just use the top code.