0

我已经开始在 UWP 应用程序中使用 Windows 组合 API 来为 UI 的元素设置动画。

视觉元素公开 RotationAngleInDegrees 和 RotationAngle 属性以及 RotationAxis 属性。

当我围绕 Y 轴为矩形对象的 RotationAngleInDegrees 值设置动画时,矩形会按预期旋转,但在 2D 应用程序窗口中,它似乎没有显示为 2.5D 投影。

有没有办法使用组合 api 获得旋转的 2.5D 投影效果?

4

2 回答 2

1

这取决于你想要的效果。GitHub 上有一个流利的设计应用程序示例,这里是链接。您将能够从商店下载演示。你可以从深度样本中得到一些想法。例如,翻转显示显示了一种旋转图像卡的方法,您可以从这里找到源代码。有关更多详细信息,请查看示例和演示。

一般来说,动画是基于X轴旋转的:

rectanglevisual.RotationAxis = new System.Numerics.Vector3(1f, 0f, 0f);

然后使用旋转动画根据 RotationAngleInDegrees 进行旋转。

您也可以使用图像控件中的PlaneProjection在 XAML 平台上直接执行此操作。

于 2019-03-06T08:02:03.480 回答
0

正如@BarryWang 指向我的示例所演示的,有必要在执行动画之前将TransformMatrix 应用于页面(或父容器),以获得具有旋转的2.5D 效果或使用组合api 的其他空间变换动画。

    private void UpdatePerspective()
    {
        Visual visual = ElementCompositionPreview.GetElementVisual(MainPanel);

        // Get the size of the area we are enabling perspective for
        Vector2 sizeList = new Vector2((float)MainPanel.ActualWidth, (float)MainPanel.ActualHeight);

        // Setup the perspective transform.
        Matrix4x4 perspective = new Matrix4x4(

                    1.0f, 0.0f, 0.0f, 0.0f,

                    0.0f, 1.0f, 0.0f, 0.0f,

                    0.0f, 0.0f, 1.0f, -1.0f / sizeList.X,

                    0.0f, 0.0f, 0.0f, 1.0f);

        // Set the parent transform to apply perspective to all children
        visual.TransformMatrix =

                           Matrix4x4.CreateTranslation(-sizeList.X / 2, -sizeList.Y / 2, 0f) *      // Translate to origin

                           perspective *                                                            // Apply perspective at origin

                           Matrix4x4.CreateTranslation(sizeList.X / 2, sizeList.Y / 2, 0f);         // Translate back to original position
    }
于 2019-03-07T19:56:54.143 回答