QML —— 顺序动画,足球落地示例(附完整源码)
效果
源码
import QtQuick 2.12
import QtQuick.Window 2.12Window
{visible: truewidth: 640height: 480title: qsTr("Hello World")MouseArea{anchors.fill: parentonClicked:{setSequentialAnimationState(true)}}Component.onCompleted:{setSequentialAnimationState(false)}Component.onDestruction:{setSequentialAnimationState(false)}function setSequentialAnimationState(b){if(b){if(!sequentialAnimation.running){sequentialAnimation.start()}}else{if(sequentialAnimation.running){sequentialAnimation.stop()}}}Image{id: ballImgsource: "ball.jpeg"scale: 0.3y: -heightanchors.horizontalCenter: parent.horizontalCenterSequentialAnimation on y{id: sequentialAnimationloops: Animation.InfiniteNumberAnimation{id: fallNumberAnimationto: ballImg.parent.height - ballImg.heighteasing.type: Easing.OutBounceduration: 2000}PauseAnimation {duration: 1000}NumberAnimation{to: -ballImg.heighteasing.type: Easing.OutQuadduration: 500}}}
}
关注
笔者 - jxd