我有一个flickable,我想要捕捉到某些位置(我以特定的方式计算) . 我看到两个选择:
-
在movingEnded中我使用数字动画捕捉到"contentX"的最近位置
-
在flickEnded中我使用数字动画捕捉到"contentX"的最近位置
选项1看起来不太好,运动停止,然后轻弹再次开始移动(捕捉位置相隔半个屏幕) .
在选项2中,我发现难以选择卡扣位置 . 如果用户以快速移动滑动,我宁愿捕捉到靠近位置的位置,移动将在此处结束,但这很难预测 .
以下是选项1的示例代码:
NumberAnimation on contentY {
id: yAnimation
to: 0
duration: 200
}
onMovementEnded: {
var index = Math.round(contentY / (itemHeight))
yAnimation.to = index * itemHeight
yAnimation.start()
}
1 回答
你有水平和垂直速度的属性,所以你可以用另一个来计算复合速度
property bool aboutToStop: horizontalVelocity + verticalVelocity < thresholdValue
和
onAboutToStopChanged: if (aboutToStop) playASnapAnimationToTheNearestItem()