如何能到达在滑动距离相对小的情况下,造成较大距离的滑动(滑动距离一样的情况下,List滑动距离变大)

已邀请:

谷主

赞同来自:

划快点。惯性滑动和加速度有关,和距离无关。

布偶FHY

赞同来自:

List禁用了惯性,手滑动距离与滚动距离感觉是1:1,有没有相关API支持设置一下

谷主

赞同来自:

没有。

fatfatson

赞同来自:

同感,滑动体验需要改进

zycpig22

赞同来自:

我也遇到了这个问题,又不想自己写一个具有惯性并换换减速的拖动。
我采取办法是在Fairgui的ScrollpPane类里加上三个属性
        /// <summary>
/// 最小惯性距离
/// /// 未开启惯性优化无效
/// </summary>
public float minInertia
{
set;
get;
} = 0F;

/// <summary>
/// 最大惯性距离
/// 未开启惯性优化无效
/// </summary>
public float maxInertia
{
set;
get;
} = 100000F;

/// <summary>
/// 是否开启惯性优化
/// </summary>
public bool openInertiaOptimize
{
set;
get;
} = false;
然后在UpdateTargetAndDuration方法里加上
                //惯性优化
//openInertiaOptimize默认关闭,防止你的修改影响到别人
if (openInertiaOptimize)
{
v2 = v2 < minInertia + 1 ? minInertia + 1 : v2;
v2 = v2 > maxInertia ? maxInertia : v2;
}
整个UpdateTargetAndDuration方法对比
        float UpdateTargetAndDuration(float pos, int axis)
{
float v = _velocity[axis];
float duration = 0;

if (pos > 0)
pos = 0;
else if (pos < -_overlapSize[axis])
pos = -_overlapSize[axis];
else
{
//以屏幕像素为基准
float v2 = Mathf.Abs(v) * _velocityScale;
//在移动设备上,需要对不同分辨率做一个适配,我们的速度判断以1136分辨率为基准
if (Stage.touchScreen)
v2 *= 1136f / Mathf.Max(Screen.width, Screen.height);

//惯性优化
//openInertiaOptimize默认关闭,防止你的修改影响到别人
if (openInertiaOptimize)
{
v2 = v2 < minInertia + 1 ? minInertia + 1 : v2;
v2 = v2 > maxInertia ? maxInertia : v2;
}
//这里有一些阈值的处理,因为在低速内,不希望产生较大的滚动(甚至不滚动)
float ratio = 0;
if (_pageMode || !Stage.touchScreen)
{
if (v2 > 500)
ratio = Mathf.Pow((v2 - 500) / 500, 2);
}
else
{
if (v2 > 1000)
ratio = Mathf.Pow((v2 - 1000) / 1000, 2);
}

if (ratio != 0)
{
if (ratio > 1)
ratio = 1;

v2 *= ratio;
v *= ratio;
_velocity[axis] = v;

//算法:v*(_decelerationRate的n次幂)= 60,即在n帧后速度降为60(假设每秒60帧)。
duration = Mathf.Log(60 / v2, _decelerationRate) / 60;

//计算距离要使用本地速度
//理论公式貌似滚动的距离不够,改为经验公式
//float change = (int)((v/ 60 - 1) / (1 - _decelerationRate));
float change = (int)(v * duration * 0.4f);
pos += change;
}
}

if (duration < TWEEN_TIME_DEFAULT)
duration = TWEEN_TIME_DEFAULT;
_tweenDuration[axis] = duration;

return pos;
}
之后设置三个新加的属性,配合原有的decelerationRate就能实现想要的功能。
我这里是设置成1000和2000。

要回复问题请先登录注册