本文介绍了Xamarin形式的360度旋转图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

In Xamarin Forms, I want to rotate an image as 360 degree. This image rotates with animation constantly at run time. Also, this image has 6 versions of different views. Think about like rotating a glass by hand.

我尝试了这个,但是没用:

I try this one but it is useless:

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

推荐答案

您可以使用Image"Rotation"属性,并根据需要通过背景线程对其进行更改,并通过RotateTo向其添加动画以控制旋转速度和起点/终点速度:

You can use the Image "Rotation" property and change it via a background thread if needed and add animate to it via RotateTo in order to control the rotation speed and start/end point speeds:

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);
        }
    }
}

弹跳:

线性:

立方:

这篇关于Xamarin形式的360度旋转图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-16 08:06