【问题标题】:360 degree image rotating in Xamarin Forms在 Xamarin Forms 中旋转 360 度图像
【发布时间】:2017-09-26 20:45:44
【问题描述】:

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

我试试这个,但是没用:

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

【问题讨论】:

标签: c# xaml xamarin xamarin.forms


【解决方案1】:

如果需要,您可以使用图像“旋转”属性并通过后台线程对其进行更改,并通过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);
        }
    }
}

弹跳:

线性:

立方:

【讨论】:

  • 非常合身。
  • 即使应用导航到另一个页面,旋转任务也不会停止执行。阻止它的唯一方法是退出应用程序
  • @Patrick 该代码只是一个示例,您需要取消/退出 while 循环:while (true) // a CancellationToken in real life
  • @SushiHangover 好的,我明白你的意思。谢谢。
【解决方案2】:

这里是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
    }
}

【讨论】:

    【解决方案3】:

    希望这个包对你有帮助 https://github.com/ilievmark/Basil.Behaviors/tree/master/sample/BehaviorsSample/Pages/Animations

    你可以使用这样的东西

               <d:CycledAnimationDecorator Cycles="10">
                    <h:SequenceHandlerExecutor WaitResult="True">
                        <s:RotateAnimation Length="800" Rotation="360" />
                        <s:RotateAnimation Length="0" Rotation="0" />
                    </h:SequenceHandlerExecutor>
                </d:CycledAnimationDecorator>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-09
      • 1970-01-01
      • 2016-03-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多