/// <summary> /// Coroutine for smooth scrolling to an new item /// </summary> /// <param name="targetValue"></param> /// <returns></returns> private IEnumerator ScrollToTarget(float targetValue) { var interpolatedFloat = new InterpolatedFloat(contentPanel.anchoredPosition.y); _stopAutoScroll = false; while (!interpolatedFloat.IsAtValue(targetValue) && !_stopAutoScroll) { interpolatedFloat.ToValue(targetValue); contentPanel.anchoredPosition = new Vector2(0, interpolatedFloat.Value); // Check, if the scroll view will scroll outside the viewport if (scrollRect.normalizedPosition.y <= 0) { scrollRect.normalizedPosition = scrollRect.viewport.anchorMin; break; } if (scrollRect.normalizedPosition.y >= 1) { scrollRect.normalizedPosition = scrollRect.viewport.anchorMax; break; } yield return(new WaitForEndOfFrame()); } }