wangjinming
private async void DoAnimistion()
{
Storyboard storyboard = new Storyboard(); using (IEnumerator<DependencyObject> enumerator = stack.Children.ToList().GetEnumerator())       //此处的stack是一个StackPanel,我要对它的子元素做动画
{ Random random
= new Random(); TimeSpan time = TimeSpan.FromSeconds(0.0); var ts = TimeSpan.FromMilliseconds(80.0); double angle = -120.0; while (enumerator.MoveNext()) { //double num = random.Next(200, 500); FrameworkElement frameworkElement = (FrameworkElement)enumerator.Current; DoubleAnimationUsingKeyFrames xdoubleAnimationUsingKeyFrames = new DoubleAnimationUsingKeyFrames(); xdoubleAnimationUsingKeyFrames.KeyFrames.Add(CreateKeyFrame(KeyTime.FromTimeSpan(time), 380)); xdoubleAnimationUsingKeyFrames.KeyFrames.Add(CreateKeyFrame(KeyTime.FromTimeSpan(time.Add(TimeSpan.FromSeconds(0.3))), 0)); Storyboard.SetTarget(xdoubleAnimationUsingKeyFrames, frameworkElement); Storyboard.SetTargetName(xdoubleAnimationUsingKeyFrames, frameworkElement.Name); Storyboard.SetTargetProperty(xdoubleAnimationUsingKeyFrames, TargetProperty.RenderTransformTranslateX); storyboard.Children.Add(xdoubleAnimationUsingKeyFrames); DoubleAnimationUsingKeyFrames ydoubleAnimationUsingKeyFrames = new DoubleAnimationUsingKeyFrames(); ydoubleAnimationUsingKeyFrames.KeyFrames.Add(CreateKeyFrame(KeyTime.FromTimeSpan(time), angle)); ydoubleAnimationUsingKeyFrames.KeyFrames.Add(CreateKeyFrame(KeyTime.FromTimeSpan(time.Add(TimeSpan.FromSeconds(0.3))), 0)); Storyboard.SetTarget(ydoubleAnimationUsingKeyFrames, frameworkElement); Storyboard.SetTargetName(ydoubleAnimationUsingKeyFrames, frameworkElement.Name); Storyboard.SetTargetProperty(ydoubleAnimationUsingKeyFrames, TargetProperty.ProjectionRotationY); storyboard.Children.Add(ydoubleAnimationUsingKeyFrames); var num3 = -1.0 * (Math.Tan(DegreesToRadians(angle)) * frameworkElement.ActualWidth); num3 += frameworkElement.ActualWidth; DoubleAnimationUsingKeyFrames zdoubleAnimationUsingKeyFrames = new DoubleAnimationUsingKeyFrames(); zdoubleAnimationUsingKeyFrames.KeyFrames.Add(CreateKeyFrame(KeyTime.FromTimeSpan(time), num3)); zdoubleAnimationUsingKeyFrames.KeyFrames.Add(CreateKeyFrame(KeyTime.FromTimeSpan(time.Add(TimeSpan.FromSeconds(0.3))), 0)); Storyboard.SetTarget(zdoubleAnimationUsingKeyFrames, frameworkElement); Storyboard.SetTargetName(zdoubleAnimationUsingKeyFrames, frameworkElement.Name); Storyboard.SetTargetProperty(zdoubleAnimationUsingKeyFrames, TargetProperty.ProjectionGlobalOffsetZ); storyboard.Children.Add(zdoubleAnimationUsingKeyFrames); time = time.Add(ts); } } storyboard.Begin();
}
public static double DegreesToRadians(double degrees)
        {
            return degrees * 2.0 * 3.1415926535897931 / 360.0;
        }

 

分类:

技术点:

相关文章:

  • 2021-09-03
  • 2021-11-08
  • 2021-09-04
  • 2022-12-23
  • 2021-07-23
  • 2021-12-29
  • 2021-12-09
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-29
  • 2021-04-06
  • 2022-12-23
相关资源
相似解决方案