【发布时间】:2021-06-09 09:39:28
【问题描述】:
我想在颤振中播放特定持续时间的彩票动画。我不想通过快进播放它。就像如果我的动画总共包含90 frames 那么如果我只想先播放30 frames 那么我可以做到这一点吗?或者像如果我的动画总共有 2 秒但我只想播放 1 秒。那么如何使用动画控制器或任何其他东西来做到这一点?
【问题讨论】:
标签: flutter flutter-animation lottie animationcontroller
我想在颤振中播放特定持续时间的彩票动画。我不想通过快进播放它。就像如果我的动画总共包含90 frames 那么如果我只想先播放30 frames 那么我可以做到这一点吗?或者像如果我的动画总共有 2 秒但我只想播放 1 秒。那么如何使用动画控制器或任何其他东西来做到这一点?
【问题讨论】:
标签: flutter flutter-animation lottie animationcontroller
好的,您可以尝试直接编辑控制器,因此您的 initState 将如下所示:
@override
void initState() {
super.initState();
_controller = AnimationController(vsync: this);
_controller.addListener(() {
print(_controller.value);
// if the full duration of the animation is 8 secs then 0.5 is 4 secs
if (_controller.value > 0.5) {
// When it gets there hold it there.
_controller.value = 0.5;
}
});
}
然后你的 lottie 小部件看起来像这样:
Lottie.asset(
'asset/path.json',
controller: _controller,
onLoaded: (comp){
_controller
..duration = comp.duration
..forward();
})
-----------下面的上一个答案-----------
没有机会检查这一点,但尝试将控制器添加到您的动画并在 onLoaded 上使用 animateTo。
Lottie.asset(
'asset/path.json',
controller: _controller,
onLoaded: (comp){
_controller.animateTo(frameNumber);
})
【讨论】:
1 second 的滞后。所以我想消除稳定帧的滞后。如果您有其他选择,请分享。在此先感谢:)