QML 动画(组合动画)
创始人
2024-05-29 23:24:15

在QML中,可以把多个动画组合成一个单一的动画。

组合动画的类型:

  • ParallelAnimation   动画同时进行(并行)
  • SequentialAnimation 动画按照顺序执行(顺序执行)

注意:将动画分组为“顺序动画”或“并行动画”后,无法单独启动和停止动画;顺序动画或并行动画必须作为一个组启动和停止。

ParallelAnimation的使用:

 使用时需要使用running开启

开启时,变换圆角、颜色和旋转角度 

Rectangle{id:rect1width: 200;height: 200x:150;y:150color: "lightBlue";radius: 10//创建一个并行的动画ParallelAnimation{running: true //开启并行动画NumberAnimation {  //修改圆角动画target: rect1properties: "radius"loops: Animation.Infiniteduration:2000from: 10to:50}ColorAnimation {  //修改颜色动画target: rect1properties: "color"loops: Animation.Infiniteduration:2000from:"lightBlue"to:"red"}RotationAnimation {  //修改角度动画target: rect1//properties: "rect1.rotation"loops: Animation.Infiniteduration:2000from:0to:360}}}

 SequentialAnimation的使用

 需要使用running开启

 开启时每过两秒变换一种颜色

Rectangle{id:rect1width: 200;height: 200x:150;y:150color: "lightBlue";radius: 10SequentialAnimation{running: trueColorAnimation{target: rect1properties: "color"from: "white"to: "black"duration: 2000}ColorAnimation{target: rect1properties: "color"from: "black"to: "red"duration: 2000}ColorAnimation{target: rect1properties: "color"from: "red"to: "green"duration: 2000}ColorAnimation{target: rect1properties: "color"from: "green"to: "lightBlue"duration: 2000}}}

SequentialAnimation和渐变的使用

实现使用彩色动画将天空从白天淡化到黑夜

Rectangle{id:rect1width: 400;height: 600x:150;y:0color: "lightBlue";radius: 10gradient: Gradient {GradientStop {position: 0.0SequentialAnimation on color {loops: Animation.InfiniteColorAnimation { from: "#14148c"; to: "#0E1533"; duration: 5000 }ColorAnimation { from: "#0E1533"; to: "#14148c"; duration: 5000 }}}GradientStop {position: 1.0SequentialAnimation on color {loops: Animation.InfiniteColorAnimation { from: "#14aaff"; to: "#437284"; duration: 5000 }ColorAnimation { from: "#437284"; to: "#14aaff"; duration: 5000 }}}}}

相关内容

热门资讯

剑桥科技涨1.18%,成交额4... 7月23日,剑桥科技涨1.18%,成交额41.97亿元,换手率8.82%,总市值622.45亿元。异...
明新旭腾涨3.65%,成交额3... 7月23日,明新旭腾涨3.65%,成交额3000.13万元,换手率1.33%,总市值23.03亿元。...
中控技术跌3.08%,成交额1... 7月23日,中控技术跌3.08%,成交额12.79亿元,换手率1.93%,总市值659.46亿元。异...
山东玻纤涨0.30%,成交额3... 7月23日,山东玻纤涨0.30%,成交额3.97亿元,换手率4.55%,总市值86.54亿元。异动分...
亚普股份涨3.45%,成交额5... 7月23日,亚普股份涨3.45%,成交额5164.51万元,换手率0.65%,总市值80.81亿元。...