2017-09-26 139 views
0

在Xamarin形式中,我想將圖像旋轉爲360度。該圖像在運行時隨着動畫不斷旋轉。此外,此圖片有6個版本的不同視圖。想想像是用手旋轉玻璃杯。旋轉Xamarin形式的360度圖像

我試試這一個,但它是無用的:

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

您可以查看此頁面上的功能。我不認爲有360度的課程,但你可以用這些屬性編寫你自己的課程。 https://developer.xamarin.com/recipes/cross-platform/xamarin-forms/controls/rotation/ –

+0

我嘗試這些方法,但我不想完全他們。我認爲你寫我自己的課是正確的。 – xamarin

回答

0

這裏是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 
    } 
} 
0

您可以使用圖像「旋轉」屬性,如果需要通過後臺線程改變它,通過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

+0

它非常合身。 – xamarin