首页 文章

以Xamarin形式旋转的360度图像

提问于
浏览
3

在Xamarin Forms中,我想将图像旋转为360度 . 此图像在运行时不断旋转动画 . 此外,此图像有6个版本的不同视图 . 想想就像用手旋转玻璃一样 .

我试试这个,但没用:

<Image Source="glass.png" RotateToY="30"/>

2 回答

  • 0

    您可以使用Image "Rotation"属性并根据需要通过后台线程更改它,并通过 RotateTo 为其添加动画,以便控制旋转速度和开始/结束点速度:

    async Task RotateImageContinously()
    {
        while (true) // a CancellationToken in real life ;-)
        {
            for (int i = 1; i < 7; i++)
            {
                if (image.Rotation >= 360f) image.Rotation = 0;
                await image.RotateTo(i * (360 / 6), 1000, Easing.CubicInOut);
            }
        }
    }
    

    弹跳:

    enter image description here

    线性:

    enter image description here

    立方体:

    enter image description here

  • 4

    这是a similar question and answers on Xamarin Forums .

    接受的答案表明:

    private async Task RotateElement(VisualElement element, CancellationToken cancellation)
    {
        while (!cancellation.IsCancellationRequested)
        {
            await element.RotateTo(360, 800, Easing.Linear);
            await element.RotateTo(0, 0); // reset to initial position
        }
    }
    

相关问题