原文:WPF编程,通过Double Animation动态旋转控件的一种方法。
版权声明:我不生产代码,我只是代码的搬运工。 https://blog.csdn.net/qq_43307934/article/details/87259162
?
?1、控件旋转,可直接调用。需要将控件的名称,旋转的角度,时间等参数传进去。
/// <summary>
/// 控件绕中心旋转动画
/// </summary>
/// <param name="element">控件名</param>
/// <param name="anglefrom">开始角度</param>
/// <param name="angleto">结束角度</param>
/// <param name="power">过渡强度1为不用过渡</param>
/// <param name="time">持续时间,例如3秒: TimeSpan(0,0,3) </param>
public void AngleEasingAnimationShow(UIElement element, double anglefrom, double angleto,int power,TimeSpan time)
{
RotateTransform angle = new RotateTransform(); //旋转
element.RenderTransform = angle;
//定义圆心位置
element.RenderTransformOrigin = new System.Windows.Point(0.5, 0.5);
//定义过渡动画,power为过度的强度
EasingFunctionBase easeFunction = new PowerEase()
{
EasingMode = EasingMode.EaseInOut,
Power = power
};
DoubleAnimation angleAnimation = new DoubleAnimation()
{
From = anglefrom, //起始值
To = angleto, //结束值
FillBehavior = FillBehavior.HoldEnd,
Duration = time, //动画播放时间
};
angle.BeginAnimation(RotateTransform.AngleProperty, angleAnimation);
}
?
原文地址:https://www.cnblogs.com/lonelyxmas/p/10729335.html
时间: 2024-11-02 23:28:53