在Xamarin形式中,我想将图像旋转为360度。该图像在运行时随着动画不断旋转。此外,此图片有6个版本的不同视图。想想像是用手旋转玻璃杯。旋转Xamarin形式的360度图像
我试试这一个,但它是无用的:
<Image Source="glass.png" RotateToY="30"/>
在Xamarin形式中,我想将图像旋转为360度。该图像在运行时随着动画不断旋转。此外,此图片有6个版本的不同视图。想想像是用手旋转玻璃杯。旋转Xamarin形式的360度图像
我试试这一个,但它是无用的:
<Image Source="glass.png" RotateToY="30"/>
这里是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
}
}
您可以使用图像“旋转”属性,如果需要通过后台线程改变它,通过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);
}
}
}
弹跳:
线性:
立方:
它非常合身。 – xamarin
您可以查看此页面上的功能。我不认为有360度的课程,但你可以用这些属性编写你自己的课程。 https://developer.xamarin.com/recipes/cross-platform/xamarin-forms/controls/rotation/ –
我尝试这些方法,但我不想完全他们。我认为你写我自己的课是正确的。 – xamarin