this.getUIContext()?.animateTo({
duration: 2000,
// 动画播放次数,设置为-1时表示无限次播放
iterations: -1,
curve: Curve.Linear
}, () => {
this.num = 360;
this.numZ = 470;
this.twonum = 450;
this.twonumZ = 470;
this.treenum = 480;
this.treenumZ = 450;
this.formnum = 610;
this.formnumZ = 630;
}); .rotate({
x: 50,
y: 0,
z: this.numZ,
angle: this.num,
centerX: 80,
centerY: 80,
}); @Entry
@Component
struct RotatingAnimationDemo {
@State num: number = 0;
@State numZ: number = 100;
@State twonum: number = 90;
@State twonumZ: number = 90;
@State treenum: number = 180;
@State treenumZ: number = 90;
@State formnum: number = 270;
@State formnumZ: number = 270;
onDidBuild(): void {
this.getUIContext()?.animateTo({
duration: 2000,
// 动画播放次数,设置为-1时表示无限次播放
iterations: -1,
curve: Curve.Linear
}, () => {
this.num = 360;
this.numZ = 470;
this.twonum = 450;
this.twonumZ = 470;
this.treenum = 480;
this.treenumZ = 450;
this.formnum = 610;
this.formnumZ = 630;
});
};
build() {
Stack() {
Row() {
}
.width(190)
.height(190)
.border({ width: { bottom: 8 }, color: 'rgb(255, 141, 249)', style: BorderStyle.Solid })
.borderRadius(90)
.rotate({
x: 50,
y: 0,
z: this.numZ,
angle: this.num,
centerX: 80,
centerY: 80,
});
Row() {
}
.width(190)
.height(190)
.border({ width: { bottom: 8 }, color: 'rgb(255, 65, 106)', style: BorderStyle.Solid })
.borderRadius(90)
// 设置组件的旋转参数
.rotate({
x: 20, // 旋转轴向量x坐标
y: 50, // 旋转轴向量y坐标
z: this.twonumZ,
angle: this.twonum, // 旋转角度
centerX: 80, // 变换中心点x轴坐标
centerY: 80,
});
Row() {
}
.width(190)
.height(190)
.border({ width: { bottom: 8 }, color: 'rgb(0, 255, 255)', style: BorderStyle.Solid })
.borderRadius(90)
.rotate({
x: 40,
y: 150,
z: this.treenumZ,
angle: this.treenum,
centerX: 80,
centerY: 80,
});
Row() {
}
.width(190)
.height(190)
.border({ width: { bottom: 8 }, color: 'rgb(252, 183, 55)', style: BorderStyle.Solid })
.borderRadius(90)
.rotate({
x: 70,
y: 0,
z: this.formnumZ,
angle: this.formnum,
centerX: 80,
centerY: 80,
});
Row() {
Text('loading...')
.fontColor(Color.White);
}
}
.width('100%')
.height('100%')
.backgroundColor('#212121')
}
} 效果图为:
