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 }}}}}

相关内容

热门资讯

用微妙的爱 呈现大地上的座座孤... 来源:北京青年报 《社火》系列 草地里的夜光龙 《三姐妹》 张晓 2019年◎后商 展览:八仙过海 ...
华润微2025交卷IDM优势正...   炒股就看金麒麟分析师研报,权威,专业,及时,全面,助您挖掘潜力主题机会! (来源:爱集微)【编...
宏达电子跌2.00%,成交额1... 2月13日,宏达电子盘中下跌2.00%,截至11:15,报49.44元/股,成交1.45亿元,换手率...
振芯科技股价跌5.02%,长信... 2月13日,振芯科技跌5.02%,截至发稿,报27.24元/股,成交4.78亿元,换手率3.06%,...
共享汽车板块走强 千里科技涨停   02月13日消息,截止11:16,共享汽车板块走强,千里科技涨停。  声明:市场有风险,投资需谨...