设为首页 收藏本站
查看: 1211|回复: 0

重新想象 Windows 8 Store Apps (19)

[复制链接]

尚未签到

发表于 2015-5-22 05:29:22 | 显示全部楼层 |阅读模式
  [源码下载]




重新想象 Windows 8 Store Apps (19) - 动画: 线性动画, 关键帧动画, 缓动动画  
作者:webabcd

介绍
重新想象 Windows 8 Store Apps 之 动画


  • 线性动画 - 共有 3 种: ColorAnimation, DoubleAnimation, PointAnimation, 它们均继承自 Timeline
  • 关键帧动画 - 共有 4 种:ColorAnimationUsingKeyFrames, DoubleAnimationUsingKeyFrames, PointAnimationUsingKeyFrames, ObjectAnimationUsingKeyFrames 它们均继承自 Timeline
  • 缓动动画 - easing
  
示例
1、演示线性动画的应用
Animation/LinearAnimation.xaml





   






































  
2、演示关键帧动画的应用
Animation/KeyFrameAnimation.xaml




































































































  
3、演示缓动动画的应用
Animation/EasingAnimation.xaml











BackEase
BounceEase
CircleEase
CubicEase
ElasticEase
ExponentialEase
PowerEase
QuadraticEase
QuarticEase
QuinticEase
SineEase






EaseIn
EaseOut
EaseInOut








































  Animation/EasingAnimation.xaml.cs



/*
* 演示缓动(easing)的应用
*
* WinRT 支持 11 种经典的缓动:
* BackEase, BounceEase, CircleEase, CubicEase, ElasticEase, ExponentialEase, PowerEase, QuadraticEase, QuarticEase, QuinticEase, SineEase
*
* EasingMode 有 3 种:
* EaseIn, EaseOut, EaseInOut
*/
using Windows.Foundation;
using Windows.UI;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Media.Animation;
using Windows.UI.Xaml.Navigation;
using Windows.UI.Xaml.Shapes;
namespace XamlDemo.Animation
{
public sealed partial class EasingAnimation : Page
{
public EasingAnimation()
{
this.InitializeComponent();
this.Loaded += EasingAnimation_Loaded;
}
void EasingAnimation_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e)
{
cboEasingFunction.SelectedIndex = 0;
cboEasingMode.SelectedIndex = 0;
}
private void cboEasingFunction_SelectionChanged_1(object sender, SelectionChangedEventArgs e)
{
EasingChanged();
}
private void cboEasingMode_SelectionChanged_1(object sender, SelectionChangedEventArgs e)
{
EasingChanged();
}
private void EasingChanged()
{
if (cboEasingFunction.SelectedIndex == -1 || cboEasingMode.SelectedIndex == -1)
return;
storyboard.Stop();
EasingFunctionBase easingFunction = null;
// 确定 Easing Function
switch ((cboEasingFunction.SelectedItem as ComboBoxItem).Content.ToString())
{
case "BackEase":
// Amplitude - 幅度,必须大于等于 0,默认值 1
easingFunction = new BackEase() { Amplitude = 1 };
break;
case "BounceEase":
// Bounces - 弹跳次数,必须大于等于 0,默认值 3
// Bounciness - 弹跳程度,必须是正数,默认值 2
easingFunction = new BounceEase() { Bounces = 3, Bounciness = 2 };
break;
case "CircleEase":
easingFunction = new CircleEase();
break;
case "CubicEase":
easingFunction = new CubicEase();
break;
case "ElasticEase":
// Oscillations - 来回滑动的次数,必须大于等于 0,默认值 3
// Springiness - 弹簧的弹度,必须是正数,默认值 3
easingFunction = new ElasticEase() { Oscillations = 3, Springiness = 3 };
break;
case "ExponentialEase":
easingFunction = new ExponentialEase();
break;
case "PowerEase":
easingFunction = new PowerEase();
break;
case "QuadraticEase":
easingFunction = new QuadraticEase();
break;
case "QuarticEase":
easingFunction = new QuarticEase();
break;
case "QuinticEase":
easingFunction = new QuinticEase();
break;
case "SineEase":
easingFunction = new SineEase();
break;
default:
break;
}
// 确定 Easing Mode
switch ((cboEasingMode.SelectedItem as ComboBoxItem).Content.ToString())
{
case "EaseIn":
easingFunction.EasingMode = EasingMode.EaseIn;
break;
case "EaseOut":
easingFunction.EasingMode = EasingMode.EaseOut;
break;
case "EaseInOut":
easingFunction.EasingMode = EasingMode.EaseInOut;
break;
default:
break;
}
// 用于演示缓动效果
aniEasingDemo.EasingFunction = easingFunction;
// 用于演示缓动轨迹
aniBallY.EasingFunction = easingFunction;
// 画出当前缓动的曲线图
            DrawEasingGraph(easingFunction);
storyboard.Begin();
}
///
/// 绘制指定的 easing 的曲线图
///
private void DrawEasingGraph(EasingFunctionBase easingFunction)
{
graph.Children.Clear();
Path path = new Path();
PathGeometry pathGeometry = new PathGeometry();
PathFigure pathFigure = new PathFigure() { StartPoint = new Point(0, 0) };
PathSegmentCollection pathSegmentCollection = new PathSegmentCollection();
// 0 - 1 之间每隔 0.005 计算出一段 LineSegment,用于显示此 0.005 时间段内的缓动曲线
for (double i = 0; i < 1; i += 0.005)
{
double x = i * graphContainer.Width;
double y = easingFunction.Ease(i) * graphContainer.Height;
LineSegment segment = new LineSegment();
segment.Point = new Point(x, y);
pathSegmentCollection.Add(segment);
}
pathFigure.Segments = pathSegmentCollection;
pathGeometry.Figures.Add(pathFigure);
path.Data = pathGeometry;
path.Stroke = new SolidColorBrush(Colors.Black);
path.StrokeThickness = 1;
graph.Children.Add(path);
}
}
}
  
OK
[源码下载]

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-69294-1-1.html 上篇帖子: 重新想象 Windows 8 Store Apps (43) 下篇帖子: 2011 MS Build大会 – Windows 8 开发相关(博客园首发)
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表