Author Topic: When can you safely call ResetPosition on UIScrollView?  (Read 9098 times)

coolaneasy

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 34
    • View Profile
When can you safely call ResetPosition on UIScrollView?
« on: July 17, 2014, 06:54:18 PM »
Hi

So I see that if you dynamically add contents to UIGrid in your scrollview and if that content takes a bit to load up, the scrollbar is non-functional(It perhaps thinks there is not enough content to scroll).

So fine I'll call ResetPosition. But the problem is that if you call it just directly its useless. You have to wait for some time until something gets done before you can call it.

Since I don't want to just blindly wait for x amount of time I wanted to know upon what can I reliably call ResetPosition on ScrollView?

Thanks

coolaneasy

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 34
    • View Profile
Re: When can you safely call ResetPosition on UIScrollView?
« Reply #1 on: July 17, 2014, 08:06:43 PM »
Btw, seems like UITable talks to the UIScrollView to dynamically update the scrollbar. Should this not happen with UIGrid as well?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: When can you safely call ResetPosition on UIScrollView?
« Reply #2 on: July 18, 2014, 06:41:56 AM »
Sure, we can do that.
  1.         /// <summary>
  2.         /// Constrain the grid's content to be within the panel's bounds.
  3.         /// </summary>
  4.  
  5.         public void ConstrainWithinPanel ()
  6.         {
  7.                 if (mPanel != null)
  8.                 {
  9.                         mPanel.ConstrainTargetToBounds(transform, true);
  10.                         UIScrollView sv = mPanel.GetComponent<UIScrollView>();
  11.                         if (sv != null) sv.UpdateScrollbars(true);
  12.                 }
  13.         }
If you ever need to update the UI immediately, use NGUITools.ImmediatelyUpdateDrawCalls.

coolaneasy

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 34
    • View Profile
Re: When can you safely call ResetPosition on UIScrollView?
« Reply #3 on: July 22, 2014, 03:04:06 PM »
Out of curiosity why did you need include this code for updating scrollbars in UIGrid's ConstrainWithinPanel already?
Seems like you would need to this on Reposition no? UITable has it.

Also not sure why you mentioned NGUITools.ImmediatelyDrawCall stuff here. How am I supposed to use it for this particular case?

Thanks

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: When can you safely call ResetPosition on UIScrollView?
« Reply #4 on: July 22, 2014, 09:42:59 PM »
"why did you need include"? Not sure what this means.

The constrain code was added to UIGrid 4 days ago, and is in the Pro repository.

Updating draw calls is just a note -- most things in NGUI cause delayed execution, as draw calls are never updated right away.

coolaneasy

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 34
    • View Profile
Re: When can you safely call ResetPosition on UIScrollView?
« Reply #5 on: August 04, 2014, 06:00:26 PM »
need include was a typo. Sorry. I meant to say why did you not include. Anyways looks like its fixed now.
Cheers..