我正在使用 QML 構建一個簡單的影片時鐘并且它可以作業,但我想要一個“掃描秒”,其中秒針連續平滑地旋轉,而不是突然從秒過渡到秒。如果沒有Behavior下面代碼中的行,我會得到一個步進秒但其他正確的行為。使用這Behavior條線,它可以完美運行,直到秒數從 59 回到 0,然后逆時針旋轉,這不是我想要的所有行為。
我讀到使用SmoothedAnimation會有所幫助,但是當我嘗試替換它時SmoothedAnimation,NumberAnimation它會步進一秒,直到 59 到 0 過渡,然后逆時針方向移動。
我如何更改它以使其僅順時針旋轉但平穩旋轉?
import QtQuick 2.0
Item {
width: 320; height: 320
Item {
property var time: new Date()
id: wallClock
Timer {
interval: 1000
running: true
repeat: true
onTriggered: wallClock.time = new Date()
}
}
Rectangle {
id: rect1
x: parent.width/2
y: parent.height/2 - 100
width: 10; height: 70
color: "red"
transform: Rotation {
origin.x: rect1.width/2
origin.y: rect1.height
angle: wallClock.time.getSeconds()*6
Behavior on angle { NumberAnimation { duration: 1000 } }
}
}
}
uj5u.com熱心網友回復:
而不是 a NumberAnimationor SmoothedAnimation,我認為 aRotationAnimation是你想要的。這樣做的好處是它允許您強制方向保持順時針。
transform: Rotation {
origin.x: rect1.width/2
origin.y: rect1.height
angle: wallClock.time.getSeconds()*6
Behavior on angle { RotationAnimation { duration: 1000; direction: RotationAnimation.Clockwise} }
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/335516.html
