代码:
public UIScrollView scrollView;
public UIGrid grid;
private float maxOffset = - 1 ;
void Start ( ) {
scrollView = this. transform. GetComponent< UIScrollView> ( ) ;
grid = this. transform. GetComponent< UIGrid> ( ) ;
scrollView. disableDragIfFits = false;
scrollView. onDragFinished + = TurnThePage;
}
private void TurnThePage ( )
{
if ( m_callBack == null) return ;
int count = grid. GetChildList ( ) . Count;
Vector3 constraint = scrollView. panel. CalculateConstrainOffset ( scrollView. bounds. min, scrollView. bounds. min) ;
switch ( scrollView. movement)
{
case UIScrollView. Movement. Horizontal:
maxOffset = grid. cellWidth * ( count - 1 ) ;
if ( constraint. x == 0f )
{
Debug. Log ( "右一页" ) ;
}
else if ( constraint. x >= maxOffset - grid. cellWidth)
{
Debug. Log ( "坐一页" ) ;
}
break ;
case UIScrollView. Movement. Vertical:
maxOffset = grid. cellHeight * ( count - 1 ) ;
if ( constraint. y == 0f )
{
Debug. Log ( "下一页" ) ;
}
else if ( constraint. y >= maxOffset - grid. cellHeight)
{
Debug. Log ( "上一页" ) ;
}
break ;
}
}