这里的新手。我用的是吐温和AnimationController。我正在尝试使用animateTo()方法,其目标是类型偏移。这个是可能的吗?
文件说:
animateTo(双目标,{持续时间,曲线: Curves.linear })→TickerFuture 将动画从其当前值驱动到目标。
AnimationController:
_controller = AnimationController(
duration: const Duration(milliseconds: 500),
vsync: this,
);AnimateTo():
_controller.animateTo(Offset(0,0))以上一行不正确:
The argument type 'Offset' can't be assigned to the parameter type 'double'.dart(argument_type_not_assignable)是否存在AnimationController的通用类型?如果没有,为什么?我知道我可以用Tween<Offset>(begin:.., end:..).animate(_controller)。但是看起来animateTo()和类似的AnimationController方法只是针对类型为double的目标。这看起来很混乱。
发布于 2019-02-27 16:40:00
不是的。AnimationController只处理双倍。
AnimationController使用的双重与吐温使用的双重有不同的含义。
AnimationController只是关于动画的进展,而吐温可以在多个转换层之后输出一个值。
因此,不仅很难将转换后的价值转换回其所代表的进展,而且还受到限制:
曲线。如果一个AnimationController应该处理任何tweenable对象,那么它也会隐式地支持曲线。
问题是,我们可以有这样的曲线:

但这引发了一个问题。正如我们在前面的gif中所看到的,经过曲线转换后,我们可以多次发出相同的值。
在这种情况下,如果控制器可以多次发出X,那么animateTo(X)的期望行为是什么?
这是没有道理的。因此,AnimationController只使用一个线性浮动值。如果我们想要更复杂的行为,我们必须使用不同的对象。
发布于 2019-02-27 16:39:44
你需要的是这个
var _controller = AnimationController(vsync: this, duration: Duration(seconds: 2));
var _animation = Tween(begin: Offset(0,0), end: Offset(5,5));
_controller.animateTo(0.5);吐温类是一个动画片,它为动画生成内插值。animateTo方法获得介于0和1之间的值(尽管您可以在AnimationController默认值为0和1的构造函数中自己定义这些界限)。例如,如果您将0.5给animateTo方法,那么您将在偏移值之间的一半处动画化。
https://stackoverflow.com/questions/54908824
复制相似问题