如何定期进行动画制作? [英] How to animate at periodic intervals?

查看:28
本文介绍了如何定期进行动画制作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个故事板,它可以让分针滑动 6 度.现在我希望分针永远每 59 秒滑动一次.故事板是否有任何属性或我可以做的任何其他方式?

I have a storyboard which animates a minute hand to slide 6 degrees. Now i want the minute hand to slide at every 59th second forever. Are there any properties of storyboard or any other way that i can do it?

我的故事板

<Storyboard
                                    x:Name="myStoryboard2">
                                    <DoubleAnimation
                                        x:Name="minuteAnimation"
                                        Storyboard.TargetName="minHandTransform"
                                        Storyboard.TargetProperty="Angle"
                                        Duration="0:0:1"
                                        From="{Binding Time, Converter={StaticResource minuteHandTransform}}"
                                        To="{Binding Time, Converter={StaticResource minuteHandTransform}}"
                                        RepeatBehavior="1x">
                                        <DoubleAnimation.EasingFunction>
                                            <SineEase
                                                EasingMode="EaseOut" />
                                        </DoubleAnimation.EasingFunction>
                                    </DoubleAnimation>
                                </Storyboard>

推荐答案

这听起来不像是您希望依靠动画来管理的事情.只需管理从每分钟后面的代码开始动画就完成了.这样做比使用神秘的转换器来控制 From/To 值要容易得多.诸如 DoubleAnimation 之类的时间轴具有一个 BeginTime 属性,但我已经看到并验证了长时间动画持续时间(例如 1 分钟或以上)在 WinRT 中遇到错误的报告.

It doesn't sound like something you would want to rely on an animation to manage. Simply manage starting the animation from code behind every minute and you are done. It would be a lot easier to do it that way than using cryptic converters to control the From/To values. A Timeline such as a DoubleAnimation has a BeginTime property, but I have seen and verified reports of long animation durations (like 1 minute or above) hitting bugs in WinRT.

编辑*(代码示例)

我通常用来按时间间隔触发事件的两种简单方法是将 DispatcherTimer 与回调事件或异步循环一起使用.

Two simple ways I commonly use to trigger events at an interval are to use a DispatcherTimer with callback events or an async loop.

1. 调度定时器

1.  DispatcherTimer

var timer = new DispatcherTimer { Interval = TimeSpane.FromSeconds(1) };
timer.Tick += (s, e) => { /* do your stuff */ };
timer.Start();

2. 异步循环

2.  async loop

RunMyLoop();

private async void RunMyLoop()
{
    while (true)
    {
        /* do your stuff */
        await Task.Delay(1000);
    }
}

这篇关于如何定期进行动画制作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆