播放和暂停Flutter动画

时间:2019-04-06 23:24:02

标签: android animation dart flutter

我试图在此页面上添加一个按钮,该按钮将(播放或暂停)背景中的wave动画。 代码链接:https://github.com/apgapg/flutter_profile/blob/master/lib/page/intro_page.dart

我尝试了很多事情,但是由于我仍然对抖动动画感到不满意,所以我仍然没有结果。

谢谢。

2 个答案:

答案 0 :(得分:3)

当您直接访问AnimationController时,此片段将在动画停止的地方开始/停止动画。

animationController.isAnimating
    ? animationController.stop()
    : animationController.forward();

此处.isAnimating属性的类型为bool,当animationController此时正在设置动画时为true。根据结果​​,.stop() / .forward()将分别停止/开始动画。

答案 1 :(得分:1)

我不知道该代码,这是我的做法。您只需要@IBAction func backToFirstScreen(_ sender: UIButton) { self.navigationController?.popViewController(animated: true) } 停止动画并Controller.reset()开始动画即可。

但是,如果您只需要启动动画一次,请使用Controller.repeat()Controller.forward()

enter image description here

Controller.reverse()