属性

  1. ● alwaysRunToEnd : bool
  2. ● loops : int
  3. ● paused : bool
  4. ● running : bool

信号

  1. ● finished()
  2. ● started()
  3. ● stopped()

方法

  1. ● complete()
  2. ● pause()
  3. ● restart()
  4. ● resume()
  5. ● start()
  6. ● stop()

Animation子类

AnchorAnimation, Animator, ParallelAnimation, ParentAnimation, PathAnimation, PauseAnimation, PropertyAction, PropertyAnimation, ScriptAction, and SequentialAnimation

PropertyAnimation

属性动画,将属性从一个状态到另一个状态切换表现为动画。

  1. PropertyAnimation {
  2. id: animateColor;
  3. target: flashingblob;
  4. properties: "color";
  5. to: "green";
  6. duration: 1000
  7. }

SequentialAnimation

顺序执行动画,内部动画执行的顺序是阻塞顺序执行的,只有前面start的动画执行完毕后才能执行后续的动画。

  1. Rectangle {
  2. width: 100; height: 100
  3. color: "red"
  4. SequentialAnimation on color //顺序执行动画
  5. {
  6. ColorAnimation { to: "yellow"; duration: 1000 }
  7. ColorAnimation { to: "blue"; duration: 1000 }
  8. }
  9. }

ColorAnimation

继承自PropertyAnimation,ColorAnimation是一种专门的PropertyAnimation,它定义了在颜色值更改时应用的动画。

属性

  1. from : color
  2. to : color

属性中近特殊指定了to、from的类型,其余皆是继承与PropertyAnimation

NumberAnimation

继承自PropertyAnimation,数字动画是一种专门的属性动画,它定义了当数值更改时要应用的动画。

属性

  1. //numberanimation内部成员
  2. ● from : real
  3. ● to : real
  4. //有propertyanimation继承而来
  5. ● duration : int
  6. ● easing
  7. ○ easing.amplitude : real
  8. ○ easing.bezierCurve : list<real>
  9. ○ easing.overshoot : real
  10. ○ easing.period : real
  11. ○ easing.type : enumeration
  12. ● exclude : list<Object>
  13. ● from : variant
  14. ● properties : string
  15. ● property : string
  16. ● target : Object
  17. ● targets : list<Object>
  18. ● to : variant
  19. //由animation继承来
  20. ● alwaysRunToEnd : bool
  21. ● loops : int
  22. ● paused : bool
  23. ● running : bool
  24. ● complete()
  25. ● finished()
  26. ● pause()
  27. ● restart()
  28. ● resume()
  29. ● start()
  30. ● started()
  31. ● stop()
  32. ● stopped()

Behavior

  1. Rectangle {
  2. width: 75; height: 75; radius: width
  3. id: ball
  4. color: "salmon"
  5. MouseArea {
  6. anchors.fill: parent
  7. onClicked: {
  8. ball.x += 20
  9. ball.y +=10
  10. }
  11. }
  12. //预先制作一个行为,针对某一个值得变化,这里当x变化时,就会触发下面的动画
  13. Behavior on x {
  14. NumberAnimation {
  15. id: bouncebehavior
  16. easing {
  17. type: Easing.OutElastic
  18. amplitude: 1.0
  19. period: 0.5
  20. }
  21. }
  22. }
  23. Behavior on y {
  24. animation: bouncebehavior
  25. }
  26. Behavior {
  27. ColorAnimation { target: ball; duration: 100 }
  28. }
  29. }

操作实例:

  1. Rectangle {
  2. id: flashingblob
  3. width: 75; height: 75
  4. color: "blue"
  5. opacity: 1.0
  6. MouseArea {
  7. anchors.fill: parent
  8. onClicked: {
  9. animateColor.start() //需要手动开启动画,动画效果是同步执行的,一个执行完再执行下一个
  10. animateOpacity.start()
  11. animateWidth.start()
  12. }
  13. }
  14. PropertyAnimation {
  15. id: animateColor;
  16. target: flashingblob;
  17. properties: "color";
  18. to: "green";
  19. duration: 1000}
  20. NumberAnimation {
  21. id: animateOpacity
  22. target: flashingblob
  23. properties: "opacity"
  24. from: 0.1
  25. to: 1.0
  26. // loops: Animation.Infinite
  27. // easing {type: Easing.OutBack; overshoot: 500}
  28. duration:2000
  29. }
  30. NumberAnimation {
  31. id: animateWidth
  32. target: flashingblob
  33. properties: "width"
  34. from: 75
  35. to: 200
  36. // loops: Animation.Infinite
  37. // easing {type: Easing.OutBack; overshoot: 500}
  38. duration:2000
  39. }
  40. }

QQ录屏20220716164159.mp4