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.
var offset = ScrollView.panel.clipOffset;
//Add new Items Here
ScrollView.ResetPosition();
ScrollView.panel.clipOffset = offset;
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.
var offset = ScrollView.panel.transform.localPosition;
// Add Items Here
yield return new WaitForEndOfFrame
();
ScrollView.ResetPosition();
// firstTime prevents the scroll from centering on the first item on load
if (!firstTime)
SpringPanel.Begin(ScrollView.panel.cachedGameObject, offset, 100f);