我正在尝试整理一个动画,我可以在其中指定速度(而不是持续时间),并且永远循环.我想出了两个不起作用的例子:
FirstTry.qml
import Qt 4.7
Rectangle {
width: 100; height: 100
Text {
text: "hello"
NumberAnimation on x {
to: 50;
loops: Animation.Infinite;
duration: 50 * Math.abs(to - from)
}
}
}
Run Code Online (Sandbox Code Playgroud)
我hello在屏幕上疯狂时得到以下运行时警告(足够公平).
QDeclarativeExpression: Expression "(function() { return 50 * Math.abs(to - from) })" depends on non-NOTIFYable properties:
QDeclarativeNumberAnimation::to
QDeclarativeNumberAnimation::from
Run Code Online (Sandbox Code Playgroud)
SecondTry.qml
import Qt 4.7
Rectangle {
width: 100; height: 100
Text {
text: "hello"
SmoothedAnimation on x {
to: 50;
loops: Animation.Infinite;
velocity: 50
}
}
}
Run Code Online (Sandbox Code Playgroud)
这更像是一种谜 - SmoothedAnimation只是拒绝循环!动画运行一次然后就是它.
所以我有以下问题:
在第一个例子中是否有合法的方法来指定速度?我理解SmoothedAnimation是源于NumberAnimation,所以也许它可能在QML中,而不仅仅是在C++中.
有办法制作SmoothedAnimation循环吗?第二个例子是不是在处理bug还是我错过了什么?
有没有其他方法可以同时实现这两种行为?
这是我作为临时解决方案所做的,我不确定它是否足够,但它似乎正在做我需要的事情。
SmoothedAnimation on x {
to: 50;
//loops: Animation.Infinite;
velocity: 50
onComplete: { restart (); }
}
Run Code Online (Sandbox Code Playgroud)
不过,我仍然对问题的答案感兴趣。