animation - 秒针的流畅动画
问题描述
我正在用 QML 构建一个简单的动画时钟,它可以工作,但我想要一个“扫秒”,其中秒针连续平稳地旋转,而不是突然从一秒过渡到另一秒。如果没有Behavior
下面代码中的行,我会得到一个第二步但在其他方面是正确的行为。有了这Behavior
条线,它可以完美地工作,直到秒数从 59 回到 0,然后它逆时针旋转,这并不是我想要的所有行为。
我读到 usingSmoothedAnimation
会有所帮助,但是当我尝试替换它时SmoothedAnimation
,NumberAnimation
它会一步一步地执行,直到 59 到 0 的转换,然后逆时针方向移动。
如何更改它以使其仅顺时针旋转但顺利进行?
import QtQuick 2.0
Item {
width: 320; height: 320
Item {
property var time: new Date()
id: wallClock
Timer {
interval: 1000
running: true
repeat: true
onTriggered: wallClock.time = new Date()
}
}
Rectangle {
id: rect1
x: parent.width/2
y: parent.height/2 - 100
width: 10; height: 70
color: "red"
transform: Rotation {
origin.x: rect1.width/2
origin.y: rect1.height
angle: wallClock.time.getSeconds()*6
Behavior on angle { NumberAnimation { duration: 1000 } }
}
}
}
解决方案
而不是 a NumberAnimation
or SmoothedAnimation
,我认为 aRotationAnimation
是你想要的。这样做的好处是它允许您强制方向保持顺时针方向。
transform: Rotation {
origin.x: rect1.width/2
origin.y: rect1.height
angle: wallClock.time.getSeconds()*6
Behavior on angle { RotationAnimation { duration: 1000; direction: RotationAnimation.Clockwise} }
}
推荐阅读
- git - git本地存储库中的`main`和`master`有什么区别?
- c# - 更新到 Visual Studio 2019 16.8.0 后应用清单验证错误
- javascript - Mongodb Atlas EConn拒绝
- dynamic - prolog动态谓词/1和/2之间的区别
- xamarin.forms - 超过 5 个选项卡 Xamarin 表单的背景颜色
- react-native - react native 62.2 up to 63 images are not able to show in IOS 14, IOS issue
- swift - Swift 包管理器目标链接
- .net - 从前端调用引用 .NET EF6 实体
- javascript - 用户使用 Apple 登录创建一个帐户,然后在我的应用程序上删除他们的帐户,他们无法创建新帐户
- spring-boot - 使用协程将 traceId 添加到 kotlin 反应式 api