過渡動畫完成後,我想更改狀態。我有以下的代碼實現了這一點,但它似乎有種的hackish:過渡動畫完成後更改狀態
import QtQuick 2.3
import QtQuick.Controls 1.2
import QtQuick.Controls.Styles 1.2
Rectangle {
id: root
width: 400
height: 400
Rectangle {
id: rect
color: "blue"
width: 50
height: 50
anchors.centerIn: parent
MouseArea {
anchors.fill: parent
onClicked: rect.state = "animating"
}
states: [
State {
name: "animating"
PropertyChanges {
target: rect
rotation: 360
}
},
State {
name: "shrinking"
PropertyChanges {
target: rect
scale: 0
}
}
]
transitions: [
Transition {
from: ""
to: "animating"
SequentialAnimation {
RotationAnimation {
duration: 500
}
ScriptAction {
script: rect.state = "shrinking"
}
}
},
Transition {
from: "animating"
to: "shrinking"
NumberAnimation {
property: "scale"
duration: 500
}
}
]
}
}
有沒有一個更好的辦法做到這一點,而無需使用ScriptAction
?請注意,我需要第二個狀態,並且我不想將縮放動畫合併到animating
轉換的SequentialAnimation
中。
這個問題是https://stackoverflow.com/questions/22902769/how-to-switch-to-another-state-at-的副本q-transition-in-qml,但您的現有解決方案比原始問題的答案更清晰。 – cmannett85 2014-09-27 09:45:00
我甚至不喜歡我的解決方案,所以我希望有更好的解決方案。 :p – Mitch 2014-09-27 10:15:57
事實上,你的國家被命名爲「縮小」而不是「縮小」,這表明它們不是真實狀態,而是過渡作爲狀態實施。你不能用SequentialAnimation合併兩個轉換嗎? – jturcotte 2014-09-28 12:33:11