import { curves } from '@kit.ArkUI'
@Entry@Componentstruct Page030 { @State rotateValue_1: number = 0 @State rotateValue_2: number = 0
build() { Column({ space: 10 }) {
Image($r("app.media.app_icon")) .width('100lpx') .height('100lpx') .rotate({ angle: this.rotateValue_1 }) .animation({ duration: 2000, curve: curves.springMotion(), playMode: PlayMode.Normal,
})
Button('切换旋转 (往返)').onClick(() => { //先正向转,再转回来 this.rotateValue_1 = this.rotateValue_1 == 360 ? 0 : 360 }) Button('持续加速旋转').onClick(() => { //持续正转,动画未执行完成就继续加速旋转 this.rotateValue_1 += 360 }) Image($r("app.media.app_icon")) .width('100lpx') .height('100lpx') .rotate({ angle: this.rotateValue_2 }) .animation(this.rotateValue_2 != 0 ? { duration: 2000, curve: curves.springMotion(), playMode: PlayMode.Normal, onFinish: (() => { console.info('----onFinish this.rotateValue', this.rotateValue_2) if (this.rotateValue_2 == 360) { this.rotateValue_2 = 0 } }) } : undefined) Button('条件旋转 (一次性)').onClick(() => { //持续正转,动画未执行完成点击无效 this.rotateValue_2 = 360 }) } .width('100%') .height('100%') }}
评论