可以响应拖拽事件的示例,参考如下:import { UIContext } from '@ohos.arkui.UIContext'; @Entry @Component struct KeyframeDemo { @State myScale: number = 1.0; uiContext: UIContext | undefined = undefined; aboutToAppear() { this.uiContext = this.getUIContext?.(); } build() { Column() { Text('ceshi') .width(100) .height(100) .margin(100) .draggable(true) .scale({ x: this.myScale, y: this.myScale }) .gesture( PanGesture({ direction: PanDirection.Left }).onActionStart(() => { console.log("success") }) ) .onClick(() => { if (!this.uiContext) { console.info("no uiContext, keyframe failed"); return; } this.myScale = 1; // 设置关键帧动画整体播放3次 this.uiContext.keyframeAnimateTo({ iterations: -1 }, [ { // 第一段关键帧动画时长为800ms,scale属性做从1到1.5的动画 duration: 800, event: () => { this.myScale = 1.5; } }, { // 第二段关键帧动画时长为500ms,scale属性做从1.5到1的动画 duration: 500, event: () => { this.myScale = 1; } } ]); }) }.width('100%').margin({ top: 5 }) } }
可以响应拖拽事件的示例,参考如下: