/// <summary> /// 异步调用缓动方法 /// </summary> /// <param name="context">需要更新UI的线程上下文</param> /// <param name="currentTime">初始缓动步数</param> /// <param name="beginPosition">初始位置</param> /// <param name="variablePosition">位置变化量</param> /// <param name="duration">目标缓动步数</param> /// <param name="sleepMillSecond">延迟时间,以毫秒为单位</param> /// <param name="animateEvent">缓动动画回调</param> public static void setOnBounceAnimateCallback(SynchronizationContext context, double currentTime, int beginPosition, int variablePosition, double duration, int sleepMillSecond, AnimateEvent animateEvent, AnimationType type) { new Thread(() => { int posi = beginPosition; while (currentTime < duration) { switch (type) { case AnimationType.EASE_IN: posi = (int)easeIn(currentTime++, beginPosition, variablePosition, duration); break; case AnimationType.EASE_OUT: posi = (int)easeOut(currentTime++, beginPosition, variablePosition, duration); break; case AnimationType.EASE_IN_OUT: posi = (int)easeInOut(currentTime++, beginPosition, variablePosition, duration); break; } context.Post((n) => { animateEvent((int)n); }, posi); Thread.Sleep(sleepMillSecond); } }).Start(); }
/// <summary> /// 异步调用缓动方法 /// </summary> /// <param name="context">需要更新UI的线程上下文</param> /// <param name="currentTime">初始缓动步数</param> /// <param name="beginPosition">初始位置</param> /// <param name="variablePosition">位置变化量</param> /// <param name="duration">目标缓动步数</param> /// <param name="sleepMillSecond">延迟时间,以毫秒为单位</param> /// <param name="animateEvent">缓动动画回调</param> public static void setOnLinerAnimateCallback(SynchronizationContext context, double currentTime, int beginPosition, int variablePosition, double duration, int sleepMillSecond, AnimateEvent animateEvent) { new Thread(() => { int posi = beginPosition; while (currentTime < duration) { posi = (int)easeIn(currentTime++, beginPosition, variablePosition, duration); context.Post((n) => { animateEvent((int)n); }, posi); Thread.Sleep(sleepMillSecond); } }).Start(); }