具有“速度”和“速度”的 QML 动画和无限“循环”
我正在尝试制作一个动画,在其中指定速度(而不是持续时间)并且永远循环。我想出了两个不起作用的示例:
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)
}
}
}
当 hello
在屏幕上发疯时,我收到以下运行时警告(这很公平)。
QDeclarativeExpression: Expression "(function() { return 50 * Math.abs(to - from) })" depends on non-NOTIFYable properties:
QDeclarativeNumberAnimation::to
QDeclarativeNumberAnimation::from
SecondTry.qml
import Qt 4.7
Rectangle {
width: 100; height: 100
Text {
text: "hello"
SmoothedAnimation on x {
to: 50;
loops: Animation.Infinite;
velocity: 50
}
}
}
这更加神秘——SmoothedAnimation
根本拒绝循环!动画运行一次,然后就这样了。
所以我有以下问题:
是否有合法的方法来指定第一个示例中的速度?我知道 SmoothedAnimation
是从 NumberAnimation
派生的,所以也许它可以在 QML 中实现,而不仅仅是在 C++ 中。
有没有办法让 SmoothedAnimation
循环?第二个示例不起作用,是错误还是我遗漏了某些内容?
有没有其他方法可以同时实现这两种行为?
I'm trying to put together an animation in which I get to specify the velocity (rather than the duration) and which loops forever. I came up with two non-working examples:
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)
}
}
}
I get the following runtime warning while hello
goes nuts on the screen (fair enough).
QDeclarativeExpression: Expression "(function() { return 50 * Math.abs(to - from) })" depends on non-NOTIFYable properties:
QDeclarativeNumberAnimation::to
QDeclarativeNumberAnimation::from
SecondTry.qml
import Qt 4.7
Rectangle {
width: 100; height: 100
Text {
text: "hello"
SmoothedAnimation on x {
to: 50;
loops: Animation.Infinite;
velocity: 50
}
}
}
This is more of a mistery -- SmoothedAnimation
simply refuses to loop! The Animation runs once and then that's it.
So I have the following questions:
Is there a legal way to specify the velocity in the first example? I understand SmoothedAnimation
is derived from NumberAnimation
, so maybe it's possible in QML, not just in C++.
Is there a way to make SmoothedAnimation
loop? Is the second example not working a bug or am I missing something?
Is there any other way to achieve these two behaviours at the same time?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
只需显式添加“from”参数:
just add "from" parameter explicitly:
这是我作为临时解决方案所做的,我不确定它是否足够,但它似乎正在做我需要的事情。
不过,我仍然对问题的答案感兴趣。
This is what I did as a temporary solution, I'm not sure if it's adequate, but it seem to be doing just what I needed.
I'm still interested in the answers to the questions, though.
即使SmoothedAnimation不接受loops参数,您也可以将其放置在SequentialAnimation内并将loops应用于此外部覆盖。作为效果,您的平滑动画将连续播放。
Even if SmoothedAnimation doesn't accept loops parameter, you can place it inside SequentialAnimation and apply loops to this external cover. As an effect your smoothed animation will be played continuosly.