如何判断NGUI的ScrollView是否正在移动

来源:互联网 发布:淘宝卖兽药 编辑:程序博客网 时间:2024/04/30 02:34

在实际项目中,我们通常需要判断ScrollView上的item是否正在移动, 在NGUI的3.7.9的版本中,其没有提供这样的属性。ScrollView仅仅提供了下面事件的注册通知:

    /// <summary>    /// Event callback to trigger when the drag process begins.    /// </summary>    public OnDragNotification onDragStarted;    /// <summary>    /// Event callback to trigger when the drag process finished. Can be used for additional effects, such as centering on some object.    /// </summary>    public OnDragNotification onDragFinished;    /// <summary>    /// Event callback triggered when the scroll view is moving as a result of momentum in between of OnDragFinished and OnStoppedMoving.    /// </summary>    public OnDragNotification onMomentumMove;    /// <summary>    /// Event callback to trigger when the scroll view's movement ends.    /// </summary>    public OnDragNotification onStoppedMoving;

它没有提供开始移动的注册通知,所以不大好弄。

其实还有一个更简单的方法:
首先,我们应该了解ScrollView (带上item)滑动或者移动的原理, 其实SrollVieW的滑动或者移动,是移动ScrollView的GameObject的位置,而Scrollview的item其实是作为ScrollView对象的子物体跟随父物体一起移动的。
然后,利用主动查看方法就很容易得到一个ScrollView是否正在移动了,具体的思想就是在update中查看ScrollView物体的位置,如果位置发生变化,就说明移动,如果没有变化,就说明没有移动。

0 0