项目场景:
提示:这里简述项目相关背景:
项目中,经常会用到加载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);
}
"
}