@Component export struct VoiceAssistant { @State isShowAssistant: boolean = true @State voiceText: string = "" @State isListening: boolean = true // 添加缩放动画状态 @State scaleValue: number = 1.0 @State isScalingUp: boolean = true aboutToAppear() { this.startBreathingAnimation() } startBreathingAnimation() { // 使用setInterval实现呼吸动画 setInterval(() => { if (this.isScalingUp) { this.scaleValue = 1.2 } else { this.scaleValue = 1.0 } // this.isScalingUp = !this.isScalingUp }, 1000) // 每1秒切换一次 } build() { Stack() { // 只在显示时才渲染 if (this.isShowAssistant) { Column() { Column(){ } .width('100%') .height('70%') .backgroundColor(Color.Transparent) .onClick(() => { this.isShowAssistant = false }) Row() { Image($r('app.media.state_microphone')) .fillColor($r('app.color.FFFFFF')) .width(50) .height(50) .scale({ x: this.scaleValue, y: this.scaleValue }) .animation({ // 添加动画修饰器 duration: 1000, curve: Curve.EaseInOut, iterations: -1, playMode: PlayMode.Alternate }) Text('') // TextInput({ placeholder: '' }) // .type(InputType.Normal) // .placeholderFont({ size: $r('app.float.fontSize_16') }) // .placeholderColor($r('app.color.30FFFFFF')) // .fontSize($r('app.float.fontSize_16')) // .fontColor($r('app.color.FFFFFF')) // //.enableKeyboardOnFocus(false) // .layoutWeight(1) // 占据剩余空间 // .onClick((event: ClickEvent) => { // event.; // 关键!阻止事件冒泡到透明背景层 // }) } .width('90%') .padding(10) .backgroundColor($r('app.color.000000')) // 半透明背景 .borderRadius(20) } .width('100%') .height('100%') .justifyContent(FlexAlign.End) // 内容底部对齐 .padding(20) } } } }