首页 > 代码库 > [UWP-小白日记13]Composition动画

[UWP-小白日记13]Composition动画

1.Composition旋转动画

第一步:创建一个Composition

       var composition = ElementCompositionPreview.GetElementVisual(this).Compositor;

第二步:创建动画

       //--------------------------------------------------------------------            // 1.创建一个ScalarAnimation和一个线性缓动函数。            //--------------------------------------------------------------------            var animation = composition.CreateScalarKeyFrameAnimation();            var easing = composition.CreateLinearEasingFunction();            //--------------------------------------------------------------------            // 1.设置动画,从0度旋转360度,3秒钟,重复播放            //--------------------------------------------------------------------            animation.InsertKeyFrame(0.0f,0.0f);            animation.InsertKeyFrame(1.0f,360.0f,easing);            animation.Duration = TimeSpan.FromMilliseconds(3000);            animation.IterationBehavior = AnimationIterationBehavior.Forever;

第三部:开始动画

       //--------------------------------------------------------------------            // 1.获取button的Visual            // 2.开始动画,中心旋转            //--------------------------------------------------------------------            var buttonVisual = ElementCompositionPreview.GetElementVisual(AnimatingButton);            buttonVisual.CenterPoint = new Vector3((float)AnimatingButton.ActualWidth/2.0f,(float)AnimatingButton.ActualHeight/2.0f,0.0f);            buttonVisual.StartAnimation(nameof(buttonVisual.RotationAngleInDegrees),animation);

 

  技术分享

[UWP-小白日记13]Composition动画