Qml 动画线程 渲染线程 还是UI主线程,Animation or Animator

项目场景:

提示:这里简述项目相关背景:

项目中,经常会用到加载loading窗口,当进行一些复杂逻辑处理时,往往加载窗口的动画效果会很卡,后来分析,是qml的动画导致。
后来通过查找资料发现PropertyAnimation,NumberAnimation,ColorAnimation、RotationAnimation等继承Animation的动画,都是直接运行在GUI线程里面的,而qml 提供了 Animator动画,是如下介绍的:

Animator types are a special type of animation which operate directly
on Qt Quick’s scene graph, rather than the QML objects and their
properties like regular Animation types do. This has the benefit that
Animator based animations can animate on the scene graph’s rendering
thread even when the UI thread is blocked.


意思是说:Animator是渲染线程上进行动画效果的。所以完美解决动画卡顿问题。

Animation

Inherited By:
OpacityAnimator, RotationAnimator, ScaleAnimator, UniformAnimator, XAnimator, and YAnimator

用法如下

ScaleAnimator {
            target: ttarget//scaleTransform
            from: 2.0
            to: 0.7
            duration: 300
                  }
  ShaderEffect {
      width: 50
      height: 50
      property variant t;
      UniformAnimator on t {
          from: 0
          to: 1
          duration: 1000
      }
      fragmentShader:
      "
          uniform lowp float t;
          varying highp vec2 qt_TexCoord0;
          void main() {
              lowp float c = qt_TexCoord0.y;
              gl_FragColor = vec4(c * t, 0, 0, 1);
          }
      "
  }

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值