pageTransition() {
PageTransitionEnter({ type: RouteType.None, duration: 0 });
PageTransitionExit({ type: RouteType.None, duration: 0 });
}
.rotate({
x: 0,
y: 1,
z: 0,
angle: this.angle,
centerX: '50%',
centerY: '50%',
centerZ: 0,
perspective: 0
});
aboutToAppear(): void {
this.result = this.getUIContext().createAnimator(this.options);
this.result.onFrame = (value: number) => {
this.angle = -value * 180;
};
this.result.onFinish = () => {
this.getUIContext().getRouter().pushUrl({ url: 'pages/Index2' });
};
}
完整代码参考如下:
import { AnimatorOptions, AnimatorResult } from '@kit.ArkUI';
@Entry
@Component
struct Index {
@State angle: number = 1;
@State result: AnimatorResult | undefined = undefined;
private options: AnimatorOptions = {
duration: 1200,
easing: 'friction',
delay: 0,
fill: 'forwards',
direction: 'normal',
iterations: 1,
begin: 0,
end: 1
};
aboutToAppear(): void {
this.result = this.getUIContext().createAnimator(this.options);
this.result.onFrame = (value: number) => {
this.angle = -value * 180;
};
this.result.onFinish = () => {
this.getUIContext().getRouter().pushUrl({ url: 'pages/Index2' });
};
}
build() {
Stack() {
Button('go to PageTwo')
.onClick(() => {
this.result?.play();
});
}
.width('100%')
.height('100%')
.backgroundColor('#f1f3f5')
.expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.TOP, SafeAreaEdge.BOTTOM])
.rotate({
x: 0,
y: 1,
z: 0,
angle: this.angle,
centerX: '50%',
centerY: '50%',
centerZ: 0,
perspective: 0
});
}
pageTransition() {
PageTransitionEnter({ type: RouteType.None, duration: 0 });
PageTransitionExit({ type: RouteType.None, duration: 0 });
}
}
import { AnimatorOptions, AnimatorResult } from '@kit.ArkUI';
@Entry
@Component
struct Index2 {
@State angle: number = 0;
@State result: AnimatorResult | undefined = undefined;
private options: AnimatorOptions = {
duration: 1200,
easing: 'friction',
delay: 0,
fill: 'forwards',
direction: 'normal',
iterations: 1,
begin: 0,
end: 1
};
aboutToAppear(): void {
this.result = this.getUIContext().createAnimator(this.options);
this.result.onFrame = (value: number) => {
this.angle = value * 180;
};
this.result.onFinish = () => {
this.getUIContext().getRouter().pushUrl({ url: 'pages/Index' });
};
}
build() {
Stack() {
Button('PageTwo')
.onClick(() => {
this.result?.play();
});
}
.width('100%')
.height('100%')
.backgroundColor('#f1f3f5')
.expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.TOP, SafeAreaEdge.BOTTOM])
.rotate({
x: 0,
y: 1,
z: 0,
angle: this.angle,
centerX: '50%',
centerY: 0,
centerZ: 0,
perspective: 0
});
}
pageTransition() {
PageTransitionEnter({ type: RouteType.None, duration: 0 });
PageTransitionExit({ type: RouteType.None, duration: 0 });
}
} 实现效果如下:
