NGUI 3.5.9
I have a scrollview with a grid and a bunch of elements. I'm adding and removing them at runtime and running into a weird issue where removing elements causes the grid to be scrolled up outside of the visible clip zone. I can either drag the contents back into view, or I can execute the "Reset Clipping Position" manually in the editor. Here's the code I'm using to remove elements:
void Foo() {
foreach (Transform child in _grid.transform) {
if (childMatchesCondition()) {
NGUITools.Destroy(child.gameObject);
break;
}
}
_gridScrollView.ResetPosition();
_grid.GetComponent<UIGrid>().Reposition();
}
It seems like it's the grid Reposition() that messes it up. If I just do ResetPosition, the list always lines up at the top of the scrollview (but then I get gaps), but if I call Reposition, it will sometimes shift up so one element is above the scrollview clip.
What I expect:
What I get:
With some larger scroll views that I have, if I filter it down to only a few elements they will often scroll all the way off the top of the screen and I can't see any of them.
Thoughts anyone? This seems like a pretty standard use case so there must be an easy way to do this properly.