在Xamarin Forms中,我想将图像旋转为360度 . 此图像在运行时不断旋转动画 . 此外,此图像有6个版本的不同视图 . 想想就像用手旋转玻璃一样 .
我试试这个,但没用:
<Image Source="glass.png" RotateToY="30"/>
您可以使用Image "Rotation"属性并根据需要通过后台线程更改它,并通过 RotateTo 为其添加动画,以便控制旋转速度和开始/结束点速度:
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); } } }
弹跳:
线性:
立方体:
这是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 } }
2 回答
您可以使用Image "Rotation"属性并根据需要通过后台线程更改它,并通过
RotateTo
为其添加动画,以便控制旋转速度和开始/结束点速度:弹跳:
线性:
立方体:
这是a similar question and answers on Xamarin Forums .
接受的答案表明: