如何旋转Lottie动画
我有一个颤抖的应用程序,正在显示一些Lottie动画。有时我需要在y轴上将动画倒180度,以便它是自身的镜像。
在C#中,可以通过将动画视觉播放器的平面投影rotationy
属性设置为180(见下文),很容易实现。
<muxc:AnimatedVisualPlayer x:Name="LottiePlayer">
<muxc:AnimatedVisualPlayer.Projection>
<PlaneProjection RotationY="180" x:Name="LottiePayerRotation"/>
</muxc:AnimatedVisualPlayer.Projection>
在Flutter中,我尝试使用rotationbox
,但这仅在X轴周围旋转。我需要围绕y轴旋转(请参见下图)。
我还尝试在transform
widget(见下文)中包装Lottie动画,但这不起作用。添加之后,Lottie动画完全消失了。我不太了解matrix4
的工作方式,上面几乎没有文档。我发现此
Transform(
transform: Matrix4(
1,0,0,0,
0,1,0,0,
0,0,1,0,
0,0,0,1,
)..rotateX(0)..rotateY(180)..rotateZ(0),
child: Lottie(
frameRate: FrameRate.max,
composition: _composition,
controller: _controller,
),
),
请注意,我不需要动画的翻转,我只想立即翻转Lottie动画,以使其看起来像是自身的镜像。因此,即时更改,而不是过渡动画。
任何帮助都可以理解。
I have a Flutter app that is showing some Lottie animations. I sometimes need to flip the animation by 180 degrees on Y axis so that it it is a mirror image of itself.
In C# this is easily achievable by setting animated visual player's plane projection rotationY
property to 180 (see below).
<muxc:AnimatedVisualPlayer x:Name="LottiePlayer">
<muxc:AnimatedVisualPlayer.Projection>
<PlaneProjection RotationY="180" x:Name="LottiePayerRotation"/>
</muxc:AnimatedVisualPlayer.Projection>
In flutter I tried using RotationBox
, but that only rotates around X axis. I need to rotate around Y axis (see image below).
I also tried wrapping Lottie animation inside Transform
widget (see below), but that doesn't work. After I added that, the Lottie animation completely disappears. I don't quite understand how Matrix4
works, there is very little documentation on it. I found this Matrix4 explanation but I still don't understand it. :-(
Transform(
transform: Matrix4(
1,0,0,0,
0,1,0,0,
0,0,1,0,
0,0,0,1,
)..rotateX(0)..rotateY(180)..rotateZ(0),
child: Lottie(
frameRate: FrameRate.max,
composition: _composition,
controller: _controller,
),
),
Note that I do not need the flip to be animated, I just want to flip the Lottie animation instantly so that it looks like a mirror image of itself. So an instant change, not a transition animated.
Any help appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我以前曾经使用过这样的东西旋转项目...不确定您是否追求的是
I have used something like this before to rotate items... not sure if its what you are after
原来我几乎拥有了!缺少的是
对齐
。默认值导致旋转进入可见区域。更改对齐方式为“中心”修复了:Turns out I almost had it! What was missing was the
alignment
. The default value was causing the rotation to get outside the visible area. Changing alignment to "center" fixed that:只需用
rotatedbox
&amp;包装小部件。给出QuarterTurns
值(0、1、2、3)假设我的小部件是右箭头的图像:
→
0 否旋转 -
> →
1
90旋转 -↓
2
180旋转 -←
3
270旋转 -↑
,如果我希望我的图像面对左侧
←
:编辑
以 axis 旋转,您需要使用
变换
窗口小部件。将
转换
属性作为matrix4
注意:您必须在
readians
中给出旋转。Simply wrap your widget with
RotatedBox
& givequarterTurns
value(0, 1, 2, 3)Assuming my widget is image of right arrow :
→
0
no rotation -→
1
90 rotation -↓
2
180 rotation -←
3
270 rotation -↑
So if I want my image to face left side
←
:EDIT
To rotate on axis, you need to use
Transform
widget.Give the
transform
property asMatrix4
NOTE: You have to give rotation in
radians
.