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

在NGUI 3.7.9版本中,判断ScrollView是否正在移动是个挑战,因为缺少开始移动的事件通知。不过,可以通过监测ScrollView GameObject在Update中的位置变化来实现。当ScrollView的位置发生变化时,可确定其正在移动;若位置未变,则视为静止。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在实际项目中,我们通常需要判断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物体的位置,如果位置发生变化,就说明移动,如果没有变化,就说明没有移动。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值