maui-animations
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinese.NET MAUI Animations
.NET MAUI 动画
Built-in ViewExtensions
内置 ViewExtensions
All animation methods are extension methods on and return for chaining.
VisualElementTask<bool>await所有动画方法都是 的扩展方法,返回 以支持 链式调用。
VisualElementTask<bool>awaitMethods
方法
| Method | Description |
|---|---|
| Animate |
| Animate |
| Animate |
| Animate |
| Animate |
| Animate |
| Animate |
| Animate |
| Relative scale increment |
| Relative rotation increment |
- defaults to 250 ms.
lengthdefaults toeasing.Easing.Linear - Call to stop all running animations on that view.
view.CancelAnimations()
| 方法 | 描述 |
|---|---|
| 对 |
| 对 |
| 对 |
| 对 |
| 对视图执行均匀缩放动画 |
| 对 |
| 对 |
| 对 |
| 相对增量缩放动画 |
| 相对增量旋转动画 |
- 默认值为250毫秒。
length默认值为easing。Easing.Linear - 调用 可停止该视图上所有正在运行的动画。
view.CancelAnimations()
Composite Animations
组合动画
csharp
// Parallel – all run at the same time
await Task.WhenAll(
view.FadeTo(1, 500),
view.ScaleTo(1.5, 500),
view.RotateTo(360, 500));
// Sequential – one after the other
await view.FadeTo(0, 250);
await view.TranslateTo(100, 0, 500);
await view.FadeTo(1, 250);csharp
// Parallel – all run at the same time
await Task.WhenAll(
view.FadeTo(1, 500),
view.ScaleTo(1.5, 500),
view.RotateTo(360, 500));
// Sequential – one after the other
await view.FadeTo(0, 250);
await view.TranslateTo(100, 0, 500);
await view.FadeTo(1, 250);Custom Animation Class
自定义 Animation 类
Use for fine-grained control with child animations and timing ratios.
Animationcsharp
var parent = new Animation();
// Child animations with begin/end ratios (0.0–1.0)
parent.Add(0.0, 0.5, new Animation(v => view.Opacity = v, 0, 1));
parent.Add(0.5, 1.0, new Animation(v => view.Scale = v, 1, 2, Easing.SpringOut));
// Commit to run
parent.Commit(
owner: view,
name: "MyAnimation",
rate: 16, // ms per frame
length: 1000, // total duration ms
easing: Easing.Linear,
finished: (v, cancelled) => { /* cleanup */ },
repeat: () => false); // return true to loop使用 类可实现对子动画和时间比例的精细控制。
Animationcsharp
var parent = new Animation();
// Child animations with begin/end ratios (0.0–1.0)
parent.Add(0.0, 0.5, new Animation(v => view.Opacity = v, 0, 1));
parent.Add(0.5, 1.0, new Animation(v => view.Scale = v, 1, 2, Easing.SpringOut));
// Commit to run
parent.Commit(
owner: view,
name: "MyAnimation",
rate: 16, // ms per frame
length: 1000, // total duration ms
easing: Easing.Linear,
finished: (v, cancelled) => { /* cleanup */ },
repeat: () => false); // return true to loopConstructor
构造函数
csharp
new Animation(
callback: v => view.Scale = v, // Action<double>
start: 0.0,
end: 1.0,
easing: Easing.CubicInOut);csharp
new Animation(
callback: v => view.Scale = v, // Action<double>
start: 0.0,
end: 1.0,
easing: Easing.CubicInOut);Cancelling
取消动画
csharp
view.AbortAnimation("MyAnimation");Gotcha: Returningfrom a child animation'struecallback does not repeat the parent animation. Only therepeatcallback passed torepeaton the parent controls parent repetition.Commit
csharp
view.AbortAnimation("MyAnimation");注意事项: 从子动画的回调中返回repeat不会重复父动画。只有传递给父动画true方法的Commit回调才能控制父动画的重复。repeat
AnimationExtensions.Animate
AnimationExtensions.Animate
Animate any property on any object:
csharp
view.Animate<double>(
name: "opacity",
transform: v => v, // Func<double, T>
callback: v => view.Opacity = v,
rate: 16,
length: 500,
easing: Easing.SinInOut,
finished: (v, cancelled) => { });可为任意对象的任意属性执行动画:
csharp
view.Animate<double>(
name: "opacity",
transform: v => v, // Func<double, T>
callback: v => view.Opacity = v,
rate: 16,
length: 500,
easing: Easing.SinInOut,
finished: (v, cancelled) => { });Easing Functions
缓动函数
| Easing | Curve |
|---|---|
| Constant speed |
| Smooth accelerate |
| Smooth decelerate |
| Smooth both |
| Sharp accelerate |
| Sharp decelerate |
| Sharp both |
| Bounce at start |
| Bounce at end |
| Spring at start |
| Spring at end |
| 缓动函数 | 曲线描述 |
|---|---|
| 匀速 |
| 平滑加速 |
| 平滑减速 |
| 先加速后减速,平滑过渡 |
| 急剧加速 |
| 急剧减速 |
| 先急剧加速后急剧减速 |
| 起始处弹跳 |
| 结束处弹跳 |
| 起始处弹性效果 |
| 结束处弹性效果 |
Custom Easing
自定义缓动函数
csharp
var customEase = new Easing(t => t * t * t);
await view.ScaleTo(2, 500, customEase);csharp
var customEase = new Easing(t => t * t * t);
await view.ScaleTo(2, 500, customEase);Accessibility: Power-Save Mode
无障碍功能:省电模式
Check before running animations. This is when the OS power-save / reduced-motion mode is active.
VisualElement.IsAnimationEnabledfalsecsharp
if (view.IsAnimationEnabled)
await view.FadeTo(1, 500);
else
view.Opacity = 1;在运行动画前,请检查 属性。当系统处于省电/减少动画模式时,该属性值为 。
VisualElement.IsAnimationEnabledfalsecsharp
if (view.IsAnimationEnabled)
await view.FadeTo(1, 500);
else
view.Opacity = 1;