HarmonyOS 在图片外层使用长按没有效果

Row(){
  Image($r('app.media.linkdood_video'))
    .width(50)
    .onClick(()=>{
      console.log('点击')
    })
}
.gesture(
  LongPressGesture()
    .onAction(() => {
      console.log('长按')
    })
)
HarmonyOS
2024-12-26 14:41:08
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
Excelsior_abit

可以把duration调小试一下例如duration:100

@Entry
@Component
export struct RangeSeekBar {
  // 进度条最大长度
  maxLength: number = 300
  // 进度条高度(展示厚度)
  lineHeight: number = 2
  // 球形滑动按钮直径
  circleDiameter: number = 28
  // 进度条最小值
  minAge: number = 18;
  // 进度条最大值
  maxAge: number = 50;
  // 是否按钮为图片背景,默认是圆形button
  isImageBg: boolean = false;
  imageHeight = 40
  imageWidth = 38
  // 进度条左边已滑动按钮和右边(不区分,因为可以交替)
  @State state1: number = 0
  @State state2: number = 0
  // 临时保存开始滑动时的坐标
  preStart: number = 0
  preEnd: number = 0
  // 最终返回值和ui展示长度之间的换算
  dp = 1
  onRangeChanged: Function = (state1: number, state2: number) => {
  }
  @State sizeValue: string = ''
  aboutToAppear(): void {
    this.dp = this.maxLength / (this.maxAge - this.minAge)
    this.state1 = 0
    this.state2 = this.maxLength
    if (this.isImageBg) {
      this.lineHeight = 9
    }
  }

  build() {
    Row(){
      Image($r('app.media.app_icon'))
        .width('50%')
        .onClick(()=>{
          console.log('点击')
        })
    }
    .gesture(
      LongPressGesture({duration:100})
        .onAction(() => {
          console.log('长按')
        })
    )

  }

  private checkBoundary(temp: number): number {
    if (temp >= this.maxLength) {
      return this.maxLength
    }
    return temp >= 0 ? temp : 0
  }

  private notifyRangeChanged() {
    const temp1 = Math.floor(this.state1 / this.dp) + this.minAge
    const temp2 = Math.ceil(this.state2 / this.dp) + this.minAge
    if (this.isRangeReverse()) {
      this.onRangeChanged(temp2, temp1)
    } else {
      this.onRangeChanged(temp1, temp2)
    }
  }

  private getLeftState(): Length {
    return this.isRangeReverse() ? this.state2 : this.state1
  }

  private isRangeReverse(): boolean {
    return this.state1 > this.state2
  }

  private getRangeWidth(): Length {
    const distance = this.state2 - this.state1
    return this.isRangeReverse() ? -distance : distance
  }
}
分享
微博
QQ
微信
回复
2024-12-26 15:58:17
相关问题
subscribeInfo.setDeviceId()没有效果
4393浏览 • 1回复 已解决
HarmonyOS 设置全局字体没有效果
306浏览 • 1回复 待解决
HarmonyOS POP颜色设置了没有效果
353浏览 • 1回复 待解决
HarmonyOS Canvas设置渐变色没有效果
449浏览 • 1回复 待解决
HarmonyOS 相机设置对焦点,没有效果
294浏览 • 1回复 待解决
HarmonyOS 音频面板拉起来没有效果
189浏览 • 1回复 待解决
长按实现各类振动效果
1200浏览 • 1回复 待解决
HarmonyOS 实现按钮长按动画效果
573浏览 • 1回复 待解决
HarmonyOS 组件有没有长按事件?
352浏览 • 1回复 待解决
如何去掉div长按的灰色效果
2749浏览 • 1回复 待解决