上一節中我們說到了Animation的兩個子類,分別是對Number和Color處理的類。你以為Animation就這點本事?No,No,No。Animation的子女多着呢,壯丁多就是勞動力呀。看看下面這位---RotationAnimation,一個專門處理rotation和 angle的類。
這個類和它姊妹們多了一個屬性,那就是direction。它可以有多種值,誰是它的世界中心就繞着誰旋轉。你問我?哦,我單身,屬於陀螺型的
下面看這個簡單的例子
import QtQuick 2.2 Rectangle{ id: rootItem width: 360 height: 240 color: "#EEEEEE" Rectangle{ id: rect width: 160 height: 60 anchors.left: parent.left anchors.leftMargin: 20 anchors.verticalCenter: parent.verticalCenter color: "red" MouseArea{ anchors.fill: parent onClicked: RotationAnimation{ target: rect to: 90 duration: 1500 direction: RotationAnimation.Counterclockwise } } }//red rect is end Rectangle{ id: blueRect width: 120 height: 60 anchors.right: parent.right anchors.rightMargin: 40 anchors.verticalCenter: parent.verticalCenter transformOrigin: Item.TopRight color: "blue" MouseArea{ anchors.fill: parent onClicked: animation.start() } RotationAnimation{ id: animation target: blueRect to: 60 duration: 1500 } } }
運行效果如下: