UWP 依赖动画及独立动画(Dependent and independent animations)


拥有如下任意特性的动画是一个独立动画:

1. 动画的Duration设置为0

2. 动画目标为UIElement.Opacity属性

3. 动画目标是UIElement属性的子属性,如:RenderTransform,Projection,Clip

4. 动画目标为Canvas.LeftCanvas.Top

5. 动画目标为Brush,并且使用了SolidColorBrush,改变颜色的动画

6. 动画为一个关键帧动画

如果你的动画不符合上面这些标准,它可能是一个依赖动画

默认情况下,动画系统不会运行一个依赖动画。所以在动画开发和测试过程中,你可能发现你的动画压根就不会动。此时,你想让动画动起来,你必须明确的使能这个依赖动画,那么必须设置EnableDependentAnimation=true但会影响UI性能


依赖动画示例:

Storyboard storyboard = new Storyboard();

DoubleAnimation animation = new DoubleAnimation();
animation.From = 40;
animation.To = 800;
animation.Duration = new Duration(TimeSpan.FromMilliseconds(5000));
animation.EnableDependentAnimation = true;// 没有这一句,动画就不动了

Storyboard.SetTarget(animation, Button01);
Storyboard.SetTargetProperty(animation, "(UIElement.Height)");

storyboard.Children.Add(animation);
storyboard.Begin();


独立动画

Storyboard storyboard = new Storyboard();

DoubleAnimation animation = new DoubleAnimation();
animation.From = 10;
animation.To = 100;
animation.Duration = new Duration(TimeSpan.FromMilliseconds(1000));
//animation.EnableDependentAnimation = true;// 没有这一句,动画也可以动

Storyboard.SetTarget(animation, Button02);
Storyboard.SetTargetProperty(animation, "(Canvas.Left)");

storyboard.Children.Add(animation);
storyboard.Begin();


以下是翻译的,翻译的很烂(原文):

Dependent and independent animations

At this point we need to introduce some important points about how the animation system works. In particular, animation interacts fundamentally with how a Windows Runtime app renders to the screen, and how that rendering uses processing threads. A Windows Runtime app always has a main UI thread, and this thread is responsible for updating the screen with current information. In addition, a Windows Runtime app has a composition thread, which is used for precalculating layouts immediately before they are shown. When you animate the UI, there's potential to cause a lot of work for the UI thread. The system must redraw large areas of the screen using fairly short time intervals between each refresh. This is necessary for capturing the latest property value of the animated property. If you're not careful, there's risk that an animation can make the UI less responsive, or will impact performance of other app features that are also on the same UI thread.

依赖动画和独立动画

现在我们需要介绍关于动画系统如何工作的关键点。特别是,动画是如何与windows运行时APP交互渲染到屏幕上,以及渲染如何使用线程进行处理。一个Windows运行时APP都有一个主UI线程,并且这个线程负责根据当前信息刷新屏幕。另外,一个Windows运行时APP还有一个构图线程,这个构图线程是用于在立刻显示之前预先计算好布局。当你使用UI产生动画时,这样会导致UI线程需要处理很多事工作,系统必须在最短的时间里重新绘制屏幕很大的区域。非常有必要捕捉最新动画属性的最新值。如果你不小心,动画将影响UI线程的响应,或者影响APP其他运行在UI线程上功能的性能。


The variety of animation that is determined to have some risk ofslowing down the UI thread is called adependentanimation. An animation not subject to this risk is anindependent animation. The distinctionbetween dependent and independent animations isn't just determined by animationtypes (DoubleAnimationand so on) as we described earlier. Instead, it's determined by which specificproperties you are animating, and other factors like inheritance andcomposition of controls. There are circumstances where even if an animation does change UI,the animation can have minimal impact to the UI thread, and can instead behandled by the composition thread as an independent animation.

被确定为具有减慢UI线程的一些风险各种动画被称为依赖动画。没有受到这个风险的动画是一个独立的动画。独立和独立动画之间的区别不只是动画类型(DoubleAnimation等等)正如我们前面所描述的。相反,它由你动画所指定的属性决定,以及其他因素,如继承和控件构造/组成。有些情况下,即使一个动画确实改变用户界面,动画可以影响轻微到UI线程,并可以由构图线程来处理一个独立的动画。


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
哔哩哔哩UWP的安装包可以在微软商店上找到,它的下载链接是:https://www.microsoft.com/store/productId/9NBLGGH5Q5FV。 你可以通过点击链接进入该页面,然后点击安装即可下载和安装哔哩哔哩UWP应用程序。 另外,如果你在使用哔哩哔哩UWP的过程中遇到了一些常见问题,你可以参考哔哩哔哩UWP官方提供的常见问题页面: https://b.nsapps.***帮助你更好地使用这个应用程序。 如果你需要使用VP9视频扩展来支持更高质量的视频播放,你也可以在微软商店上下载和安装VP9视频扩展,下载链接是:https://www.microsoft.com/store/productId/9N4D0MSMP0PT。 安装VP9视频扩展后,你可以享受更高质量的视频播放体验。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [Win10/Win11下图片扩展安装 HEVC/HEIF/CR2等](https://blog.csdn.net/u013130545/article/details/125976932)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* [哔哩哔哩UWP Ver4.3.8_x64](https://download.csdn.net/download/Black_Boa/86506997)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值