原文:WPF编程,通过Double Animation同时动态缩放和旋转控件的一种方法。
版权声明:我不生产代码,我只是代码的搬运工。 https://blog.csdn.net/qq_43307934/article/details/87260287
?1、 可直接调用。需要将控件的名称,缩放的位数,时间等参数传进去。?
/// <summary>
/// 同时旋转和缩放的动画
/// </summary>
/// <param name="element"></param>
/// <param name="Sizefrom"></param>
/// <param name="Sizeto"></param>
/// <param name="anglefrom"></param>
/// <param name="angleto"></param>
/// <param name="time"></param>
/// <param name="Power"></param>
/// <param name="completed"></param>
public void ScaleEasingAnimationShow(UIElement element,double Sizefrom,double Sizeto,int anglefrom, int angleto ,TimeSpan time,int Power,EventHandler completed)
{
RotateTransform angle = new RotateTransform(); //旋转
ScaleTransform scale = new ScaleTransform(); //缩放
TransformGroup group = new TransformGroup();
group.Children.Add(scale);
group.Children.Add(angle);
element.RenderTransform = group;
//定义圆心位置
//元素开始的位置是从new Point(0,0)到new Point(1,1),
//左上角为(0,0)、右下角为(1,1),控件大小范围为(1,0) 1为控件本身大小,0 为控件缩放完,不显示。
element.RenderTransformOrigin = new System.Windows.Point(0.5, 0.5);
//载入动画,淡入淡出等。
EasingFunctionBase easeFunction = new PowerEase()
{
EasingMode = EasingMode.EaseInOut,
Power = Power
};
//缩放动画
DoubleAnimation scaleAnimation = new DoubleAnimation()
{
From = Sizefrom, //起始值
To = Sizeto, //结束值
EasingFunction = easeFunction, //缓动函数
Duration = time, //动画播放时间
};
//旋转动画
DoubleAnimation angleAnimation = new DoubleAnimation()
{
From = anglefrom, //起始值
To = angleto, //结束值
EasingFunction = easeFunction, //缓动函数
FillBehavior = FillBehavior.HoldEnd,
Duration = time, //动画播放时间
};
angleAnimation.Completed += completed;
//scaleAnimation.Completed += new EventHandler(scaleAnimation_Completed);
// AnimationClock clock = scaleAnimation.CreateClock();
scale.BeginAnimation(ScaleTransform.ScaleXProperty, scaleAnimation);
scale.BeginAnimation(ScaleTransform.ScaleYProperty, scaleAnimation);
angle.BeginAnimation(RotateTransform.AngleProperty, angleAnimation);
}
?
原文地址:https://www.cnblogs.com/lonelyxmas/p/10729330.html
时间: 2024-10-03 21:41:15