Skip to content

Commit 524ce59

Browse files
peter8015zhanghaibingchengluAmosHuKe
authored
[完成翻译] src/content/cookbook/effects/staggered-menu-animation.md (#1501)
fixes: #1176 --------- Co-authored-by: zhanghaibing <[email protected]> Co-authored-by: Luke Cheng <[email protected]> Co-authored-by: Amos <[email protected]>
1 parent 3b19325 commit 524ce59

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

src/content/cookbook/effects/staggered-menu-animation.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,39 @@ In this recipe, you build a drawer menu with animated
2020
content that is staggered and has a button that pops
2121
in at the bottom.
2222

23+
一个应用的单个屏幕可能包含多个动画。
24+
所有动画同时播放可能会显得过于混乱。
25+
而依次播放动画又可能花费太长时间。
26+
更好的选择是错开动画的播放时间。
27+
每个动画在不同的时间开始,
28+
但这些动画会重叠播放,从而缩短整体持续时间。
29+
在这个示例中,你将构建一个带有动画内容的抽屉菜单,
30+
动画会交错播放,并且底部会有一个弹出的按钮。
31+
2332
The following animation shows the app's behavior:
2433

34+
以下动画展示了应用的行为:
35+
2536
![Staggered Menu Animation Example](/assets/images/docs/cookbook/effects/StaggeredMenuAnimation.webp){:.site-mobile-screenshot}
2637

2738
## Create the menu without animations
2839

40+
## 创建没有动画的菜单
41+
2942
The drawer menu displays a list of titles,
3043
followed by a Get started button at
3144
the bottom of the menu.
3245

46+
抽屉菜单显示了一系列标题,
47+
菜单底部有一个 “Get started” 按钮。
48+
3349
Define a stateful widget called `Menu`
3450
that displays the list and button
3551
in static locations.
3652

53+
定义一个名为 `Menu` 的 stateful widget,
54+
该 widget 在固定位置显示列表和按钮。
55+
3756
<?code-excerpt "lib/step1.dart (step1)"?>
3857
```dart
3958
class Menu extends StatefulWidget {
@@ -122,13 +141,20 @@ class _MenuState extends State<Menu> {
122141

123142
## Prepare for animations
124143

144+
## 为动画做好准备
145+
125146
Control of the animation timing requires an
126147
`AnimationController`.
127148

149+
控制动画时序需要一个 `AnimationController`
150+
128151
Add the `SingleTickerProviderStateMixin`
129152
to the `MenuState` class. Then, declare and
130153
instantiate an `AnimationController`.
131154

155+
`SingleTickerProviderStateMixin` 添加到 `MenuState` 类中。
156+
然后,声明并实例化一个 `AnimationController`
157+
132158
<?code-excerpt "lib/step2.dart (animation-controller)" plaster="none"?>
133159
```dart
134160
class _MenuState extends State<Menu> with SingleTickerProviderStateMixin {
@@ -154,6 +180,10 @@ up to you. Define the animation delays,
154180
individual animation durations, and the total
155181
animation duration.
156182

183+
每个动画之前的延迟时长由你决定。
184+
定义动画延迟、单个动画持续时间和总动画持续时间。
185+
186+
157187
<?code-excerpt "lib/animation_delays.dart (delays)" plaster="none"?>
158188
```dart
159189
class _MenuState extends State<Menu> with SingleTickerProviderStateMixin {
@@ -179,12 +209,25 @@ After the last list item begins to slide in,
179209
the button at the bottom waits another 150 ms to pop in.
180210
The button animation takes 500 ms.
181211

212+
在这个示例中,所有动画都延迟了 50 毫秒。
213+
随后,列表项开始出现。
214+
每个列表项的出现会比上一个列表项开始向左滑入延迟 50 毫秒。
215+
每个列表项从右向左滑入需要 250 毫秒。
216+
在最后一个列表项开始向左滑入之后,
217+
底部的按钮会再等待 150 毫秒弹出。
218+
按钮动画需要 500 毫秒。
219+
182220
With each delay and animation duration defined,
183221
the total duration is calculated so that it can be
184222
used to calculate the individual animation times.
185223

224+
在定义每个延迟和动画持续时间后,
225+
计算出总持续时间,以便用于计算各个动画的时间。
226+
186227
The desired animation times are shown in the following diagram:
187228

229+
所需的动画时间如下图所示:
230+
188231
![Animation Timing Diagram](/assets/images/docs/cookbook/effects/TimingDiagram.png){:.site-mobile-screenshot}
189232

190233
To animate a value during a subsection of a larger animation,
@@ -197,9 +240,19 @@ end times. For example, given an animation that takes 1 second,
197240
an interval from 0.2 to 0.5 would start at 200 ms
198241
(20%) and end at 500 ms (50%).
199242

243+
为了在一个较大的动画中,对某些动画值进行分段处理,
244+
Flutter 提供了 `Interval` 类。
245+
`Interval` 接受一个开始时间百分比和一个结束时间百分比。
246+
然后,可以使用该 `Interval` 在开始和结束时间之间对值进行动画处理,
247+
而不是使用整个动画的开始和结束时间。
248+
例如,对于一个持续 1 秒的动画,
249+
Interval(0.2, 0.5) 将在 200 毫秒(20%)开始,并在 500 毫秒(50%)结束。
250+
200251
Declare and calculate each list item's `Interval` and the
201252
bottom button `Interval`.
202253

254+
声明并且计算每个列选项的 `Interval` 和底部按钮的 `Interval`
255+
203256
<?code-excerpt "lib/step3.dart (step3)" plaster="none"?>
204257
```dart
205258
class _MenuState extends State<Menu> with SingleTickerProviderStateMixin {
@@ -243,10 +296,16 @@ class _MenuState extends State<Menu> with SingleTickerProviderStateMixin {
243296

244297
## Animate the list items and button
245298

299+
## 对列表项和按钮进行动画处理
300+
246301
The staggered animation plays as soon as the menu becomes visible.
247302

303+
交错动画会在菜单可见时立即播放
304+
248305
Start the animation in `initState()`.
249306

307+
`initState()` 中启动播放。
308+
250309
<?code-excerpt "lib/step4.dart (init-state)"?>
251310
```dart
252311
@override
@@ -265,10 +324,15 @@ void initState() {
265324
Each list item slides from right to left and
266325
fades in at the same time.
267326

327+
每个列表项从右到左滑动的同时逐渐淡入。
328+
268329
Use the list item's `Interval` and an `easeOut`
269330
curve to animate the opacity and translation
270331
values for each list item.
271332

333+
使用列表项的 `Interval``easeOut` 曲线 (curve)
334+
来为每个列表项的不透明度和位移值进行动画处理。
335+
272336
<?code-excerpt "lib/step4.dart (build-list-items)"?>
273337
```dart
274338
List<Widget> _buildListItems() {
@@ -311,6 +375,9 @@ Use the same approach to animate the opacity and
311375
scale of the bottom button. This time, use an
312376
`elasticOut` curve to give the button a springy effect.
313377

378+
使用相同的方法来为底部按钮的不透明度和缩放比例进行动画处理。
379+
这次,使用 `elasticOut` 曲线 (curve) 为按钮提供弹性效果。
380+
314381
<?code-excerpt "lib/step4.dart (build-get-started)"?>
315382
```dart
316383
Widget _buildGetStartedButton() {
@@ -355,8 +422,15 @@ You have an animated menu where the appearance of each
355422
list item is staggered, followed by a bottom button that
356423
pops into place.
357424

425+
恭喜!
426+
你有了一个动画菜单,
427+
每个列表项都是交错出现的,
428+
接着底部的按钮会弹出显示。
429+
358430
## Interactive example
359431

432+
## 交互示例
433+
360434
<?code-excerpt "lib/main.dart"?>
361435
```dartpad title="Flutter staggered menu animation hands-on example in DartPad" run="true"
362436
import 'package:flutter/material.dart';

0 commit comments

Comments
 (0)