简单数字动画
你可能遇到的最基本的动画之一是 NumberAnimation
。此动画通过将项目属性的数值从初始状态更改为最终状态来工作。考虑以下完整示例:
import QtQuick 2.7
import QtQuick.Controls 2.0
ApplicationWindow {
visible: true
width: 400
height: 640
Rectangle{
id: rect
anchors.centerIn: parent
height: 100
width: 100
color: "blue"
MouseArea{
anchors.fill: parent
onClicked: na.running = true
}
NumberAnimation {
id: na //ID of the QML Animation type
target: rect //The target item on which the animation should run
property: "height" //The property of the target item which should be changed by the animator to show effect
duration: 200 //The duration for which the animation should run
from: rect.height //The initial numeric value of the property declared in 'property'
to: 200 //The final numeric value of the property declared in 'property'
}
}
}