实现效果图:
private UIScrollView fubenScrollView;
private UIGrid fubenGrid;
public void OnBtnRight()//右btn
{
if (fubenScrollView == null || fubenGrid == null)
return;
int curIndex = GetFubenScrollViewIndex();
Vector3 targetPos = new Vector3(-(curIndex + 1) * fubenGrid.cellWidth, fubenScrollView.transform.localPosition.y, 0);
CapterData chapterData;
if (CapterManager.Instance.getCapterDataById(currentChapterId.ToString(), out chapterData))
{
List<int> fubenIds = chapterData.Commonfubens;
if (targetPos.x < - ((fubenIds.Count - 4) * fubenGrid.cellWidth + 10))
{
return;
}
}
SpringPanel.Begin(fubenScrollView.panel.cachedGameObject, targetPos, 6f);
}
public void OnBtnLeft()//左btn
{
if (fubenScrollView == null || fubenGrid == null)
return;
int curIndex = GetFubenScrollViewIndex();
Vector3 targetPos = new Vector3(-(curIndex - 1) * fubenGrid.cellWidth, fubenScrollView.transform.localPosition.y, 0);
if (targetPos.x > 10)
{
return;
}
SpringPanel.Begin(fubenScrollView.panel.cachedGameObject, targetPos, 6f);
}
private int GetFubenScrollViewIndex()
{
if (fubenScrollView == null || fubenGrid == null)
return 0;
return Mathf.Abs(Mathf.RoundToInt(fubenScrollView.transform.localPosition.x / fubenGrid.cellWidth));
}