如何旋转Lottie动画

发布于 2025-01-22 03:49:07 字数 1264 浏览 2 评论 0原文

我有一个颤抖的应用程序,正在显示一些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).

rotation planes

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

感情废物 2025-01-29 03:49:07

我以前曾经使用过这样的东西旋转项目...不确定您是否追求的是

child: Transform.rotate(
              angle: 180 / Math.pi, // Rotations are supplied in radians
               child: Container())

I have used something like this before to rotate items... not sure if its what you are after

child: Transform.rotate(
              angle: 180 / Math.pi, // Rotations are supplied in radians
               child: Container())
清君侧 2025-01-29 03:49:07

原来我几乎拥有了!缺少的是对齐。默认值导致旋转进入可见区域。更改对齐方式为“中心”修复了:

child: Transform(
        alignment: FractionalOffset.center,
        transform: Matrix4(
          1,0,0,0,
          0,1,0,0,
          0,0,1,0,
          0,0,0,1,
        )..rotateY(180),
        child: Lottie(
          frameRate: FrameRate.max,
          composition: _composition,
          controller: _controller,
        ),

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:

child: Transform(
        alignment: FractionalOffset.center,
        transform: Matrix4(
          1,0,0,0,
          0,1,0,0,
          0,0,1,0,
          0,0,0,1,
        )..rotateY(180),
        child: Lottie(
          frameRate: FrameRate.max,
          composition: _composition,
          controller: _controller,
        ),
套路撩心 2025-01-29 03:49:07

只需用rotatedbox&amp;包装小部件。给出QuarterTurns值(0、1、2、3)

假设我的小部件是右箭头的图像:

0 否旋转 - > →

1 90旋转 -

2 180旋转 -

3 270旋转 -

,如果我希望我的图像面对左侧

RotatedBox(
    quarterTurns: 2,
    child: Image.asset('assets/right_arrow.png'),
),

编辑

axis 旋转,您需要使用变换窗口小部件。
转换属性作为matrix4

注意:您必须在readians中给出旋转。

import 'dart:math' as math; 

Transform(
    // to mirror, rotate Y axis
    // math.pi is 180 degree in radian 
    transform: Matrix4.rotationY(math.pi), 
    child: Text('Hello world!'),
),

Simply wrap your widget with RotatedBox & give quarterTurns 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 :

RotatedBox(
    quarterTurns: 2,
    child: Image.asset('assets/right_arrow.png'),
),

EDIT

To rotate on axis, you need to use Transform widget.
Give the transform property as Matrix4

NOTE: You have to give rotation in radians.

import 'dart:math' as math; 

Transform(
    // to mirror, rotate Y axis
    // math.pi is 180 degree in radian 
    transform: Matrix4.rotationY(math.pi), 
    child: Text('Hello world!'),
),
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文