SpringAnimation QML Type

允许属性以类似弹簧的运动方式跟踪数值。更多

Import Statement: import QtQuick
Inherits:

NumberAnimation

属性

详细说明

SpringAnimation 模拟弹簧的振荡行为,使用适当的spring 常量控制加速度,使用damping 控制效果消失的速度。

您还可以限制动画的最大velocity

下面的Rectangle 使用 SpringAnimation 在鼠标点击时移动到鼠标的位置。在xy 值上使用Behavior 表示,只要这些值发生变化,就会应用 SpringAnimation。

import QtQuick

Item {
    width: 300; height: 300

    Rectangle {
        id: rect
        width: 50; height: 50
        color: "red"

        Behavior on x { SpringAnimation { spring: 2; damping: 0.2 } }
        Behavior on y { SpringAnimation { spring: 2; damping: 0.2 } }
    }

    MouseArea {
        anchors.fill: parent
        onClicked: (mouse)=> {
            rect.x = mouse.x - rect.width/2
            rect.y = mouse.y - rect.height/2
        }
    }
}

与其他动画类型一样,SpringAnimation 可通过多种方式应用,包括过渡、行为和属性值源。 Qt Quick 文档 中的动画和过渡显示了创建动画的多种方法。

另请参阅 SmoothedAnimation Qt Quick 中的动画和过渡Qt Quick 示例 - 动画,以及Qt Quick 演示 - 时钟

属性文档

damping : real

该属性保存弹簧阻尼值。

该值描述了弹簧状运动静止的速度。默认值为 0。

有效值范围为 0 - 1.0。数值越小,静止的速度越快。


epsilon : real

该属性包含弹簧ε。

ε是指数值的变化率和变化量,该值与 0 足够接近,可以认为等于零。这取决于数值的用途。对于像素位置,0.25 就足够了。对于比例,0.005 就足够了。

默认值为 0.01。调整该值可以略微提高性能。


mass : real

该属性用于保存被移动属性的 "质量"。

默认值为 1.0。

质量越大,移动速度越慢,物品静止时的弹力越大。


modulus : real

此属性保存模量值。默认值为 0。

设置modulus 会强制目标值 "环绕 "模量。例如,将模量设置为 360 会使 370 的值绕到 10。


spring : real

该属性描述了目标值被拉向源的强度。默认值为 0(即禁用弹簧运动)。

有效值范围为 0 - 5.0。

当设置该属性且velocity 值大于 0 时,velocity 限制最大速度。


velocity : real

该属性用于保存跟踪源时允许的最大速度。

默认值为 0(无最大速度)。


© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.