Animates changes in rotation values. 更多...
导入语句: | import QtQuick 2.2 |
继承: | PropertyAnimation |
RotationAnimation is a specialized PropertyAnimation that gives control over the direction of rotation during an animation.
By default, it rotates in the direction of the numerical change; a rotation from 0 to 240 will rotate 240 degrees clockwise, while a rotation from 240 to 0 will rotate 240 degrees counterclockwise. The direction property can be set to specify the direction in which the rotation should occur.
In the following example we use RotationAnimation to animate the rotation between states via the shortest path:
import QtQuick 2.0 Item { width: 300; height: 300 Rectangle { id: rect width: 150; height: 100; anchors.centerIn: parent color: "red" antialiasing: true states: State { name: "rotated" PropertyChanges { target: rect; rotation: 180 } } transitions: Transition { RotationAnimation { duration: 1000; direction: RotationAnimation.Counterclockwise } } } MouseArea { anchors.fill: parent; onClicked: rect.state = "rotated" } }
Notice the RotationAnimation did not need to set a
target
value. As a convenience, when used in a transition, RotationAnimation will rotate all properties named "rotation" or "angle". You can override this by providing your own properties via
properties
or
property
.
Also, note the
Rectangle
will be rotated around its default
transformOrigin
(which is
Item.Center
). To use a different transform origin, set the origin in the
PropertyChanges
object and apply the change at the start of the animation using
PropertyAction
。见
PropertyAction
文档编制了解更多细节。
Like any other animation type, a RotationAnimation can be applied in a number of ways, including transitions, behaviors and property value sources. The Qt Quick 中的动画和过渡 documentation shows a variety of methods for creating animations.
另请参阅 Qt Quick 中的动画和过渡 and Qt Quick Examples - Animation .
direction : enumeration |
This property holds the direction of the rotation.
Possible values are:
from : real |
This property holds the starting value for the animation.
For example, the following animation is not applied until the
angle
value has reached 100:
Item { states: [ // ... ] transitions: Transition { RotationAnimation { properties: "angle"; from: 100; duration: 2000 } } }
若 RotationAnimation is defined within a Transition or 行为 , this value defaults to the value defined in the starting state of the Transition , or the current value of the property at the moment the 行为 被触发。
另请参阅 Qt Quick 中的动画和过渡 .
to : real |
This property holds the end value for the animation..
若 RotationAnimation is defined within a Transition or 行为 , this value defaults to the value defined in the end state of the Transition , or the value of the property change that triggered the 行为 .
另请参阅 Qt Quick 中的动画和过渡 .