Author Topic: Setting the Panels Offset  (Read 4361 times)

Quarkism

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 48
    • View Profile
Setting the Panels Offset
« on: March 17, 2014, 03:02:41 PM »
I'm working on an Infinite scroll panel. When the scroll bar attached to the scroll view reaches 100%, I load more items into the scroll panel. I noticed when I loaded the new items the scroll panel's offset and scroll bar value would reset 'to the top' (in my case the top of the panel is an offset of Y -180). No other values changed.

So, I adjusted my code to save the panels offset before new items are loaded and reapply it after the new items have been added.

  1. var offset = ScrollView.panel.clipOffset;
  2. //Add new Items Here
  3. ScrollView.ResetPosition();
  4. ScrollView.panel.clipOffset = offset;
  5.  

When I do this the panel's center value changes negating my changes. In other words, the panel's offset is -355Y (as I wanted) but due to the change in the panel's center, -355Y is equivalent to -180Y. This change in the panel's center does not occur if I leave the panel's offset alone.

How can I adjust a panels offset without altering the center value ?

Edit, Looking at the code, I think this might have something to do with my use of anchors. The scroll view is anchored to take up most of the screen (minus the header above and a scroll bar to the right). I tried using the scroll view without anchoring it's panel, but that made the scroll view 'jump around' whenever items were loaded.



Edit, I tried adjusting the panel's local position (such as in the CenterOnClick script), and I am having the same issue. The panel's center changes to negate my manual local positioning.

Edit, I have a working solution.

  1. var offset = ScrollView.panel.transform.localPosition;
  2. // Add Items Here
  3.  
  4. yield return new WaitForEndOfFrame();
  5.  
  6.  ScrollView.ResetPosition();
  7.  
  8. // firstTime prevents the scroll from centering on the first item on load
  9. if (!firstTime)
  10.   SpringPanel.Begin(ScrollView.panel.cachedGameObject, offset, 100f);
  11.  
  12.  
« Last Edit: March 17, 2014, 08:31:39 PM by Quarkism »