Author Topic: Set UI Scroll View position  (Read 5360 times)

erre

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 6
    • View Profile
Set UI Scroll View position
« 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

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Set UI Scroll View position
« Reply #1 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.