属性
● alwaysRunToEnd : bool
● loops : int
● paused : bool
● running : bool
信号
● finished()
● started()
● stopped()
方法
● complete()
● pause()
● restart()
● resume()
● start()
● stop()
Animation子类
AnchorAnimation, Animator, ParallelAnimation, ParentAnimation, PathAnimation, PauseAnimation, PropertyAction, PropertyAnimation, ScriptAction, and SequentialAnimation
PropertyAnimation
属性动画,将属性从一个状态到另一个状态切换表现为动画。
PropertyAnimation {
id: animateColor;
target: flashingblob;
properties: "color";
to: "green";
duration: 1000
}
SequentialAnimation
顺序执行动画,内部动画执行的顺序是阻塞顺序执行的,只有前面start的动画执行完毕后才能执行后续的动画。
Rectangle {
width: 100; height: 100
color: "red"
SequentialAnimation on color //顺序执行动画
{
ColorAnimation { to: "yellow"; duration: 1000 }
ColorAnimation { to: "blue"; duration: 1000 }
}
}
ColorAnimation
继承自PropertyAnimation,ColorAnimation是一种专门的PropertyAnimation,它定义了在颜色值更改时应用的动画。
属性
from : color
to : color
属性中近特殊指定了to、from的类型,其余皆是继承与PropertyAnimation
NumberAnimation
继承自PropertyAnimation,数字动画是一种专门的属性动画,它定义了当数值更改时要应用的动画。
属性
//numberanimation内部成员
● from : real
● to : real
//有propertyanimation继承而来
● duration : int
● easing
○ easing.amplitude : real
○ easing.bezierCurve : list<real>
○ easing.overshoot : real
○ easing.period : real
○ easing.type : enumeration
● exclude : list<Object>
● from : variant
● properties : string
● property : string
● target : Object
● targets : list<Object>
● to : variant
//由animation继承来
● alwaysRunToEnd : bool
● loops : int
● paused : bool
● running : bool
● complete()
● finished()
● pause()
● restart()
● resume()
● start()
● started()
● stop()
● stopped()
Behavior
Rectangle {
width: 75; height: 75; radius: width
id: ball
color: "salmon"
MouseArea {
anchors.fill: parent
onClicked: {
ball.x += 20
ball.y +=10
}
}
//预先制作一个行为,针对某一个值得变化,这里当x变化时,就会触发下面的动画
Behavior on x {
NumberAnimation {
id: bouncebehavior
easing {
type: Easing.OutElastic
amplitude: 1.0
period: 0.5
}
}
}
Behavior on y {
animation: bouncebehavior
}
Behavior {
ColorAnimation { target: ball; duration: 100 }
}
}
操作实例:
Rectangle {
id: flashingblob
width: 75; height: 75
color: "blue"
opacity: 1.0
MouseArea {
anchors.fill: parent
onClicked: {
animateColor.start() //需要手动开启动画,动画效果是同步执行的,一个执行完再执行下一个
animateOpacity.start()
animateWidth.start()
}
}
PropertyAnimation {
id: animateColor;
target: flashingblob;
properties: "color";
to: "green";
duration: 1000}
NumberAnimation {
id: animateOpacity
target: flashingblob
properties: "opacity"
from: 0.1
to: 1.0
// loops: Animation.Infinite
// easing {type: Easing.OutBack; overshoot: 500}
duration:2000
}
NumberAnimation {
id: animateWidth
target: flashingblob
properties: "width"
from: 75
to: 200
// loops: Animation.Infinite
// easing {type: Easing.OutBack; overshoot: 500}
duration:2000
}
}