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

Row(){
  Image($r('app.media.linkdood_video'))
    .width(50)
    .onClick(()=>{
      console.log('点击')
    })
}
.gesture(
  LongPressGesture()
    .onAction(() => {
      console.log('长按')
    })
)
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
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
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.
  • 69.
  • 70.
  • 71.
  • 72.
  • 73.
  • 74.
  • 75.
  • 76.
  • 77.
  • 78.
  • 79.
  • 80.
  • 81.
  • 82.
  • 83.
  • 84.
分享
微博
QQ
微信
回复
2024-12-26 15:58:17
相关问题
subscribeInfo.setDeviceId()没有效果
4727浏览 • 1回复 已解决
HarmonyOS 设置全局字体没有效果
624浏览 • 1回复 待解决
HarmonyOS POP颜色设置了没有效果
689浏览 • 1回复 待解决
HarmonyOS Canvas设置渐变色没有效果
821浏览 • 1回复 待解决
HarmonyOS 相机设置对焦点,没有效果
635浏览 • 1回复 待解决
HarmonyOS 音频面板拉起来没有效果
584浏览 • 1回复 待解决
长按实现各类振动效果
1620浏览 • 1回复 待解决
HarmonyOS 实现按钮长按动画效果
1131浏览 • 1回复 待解决
HarmonyOS Vibration如何实现长按震动效果
1048浏览 • 1回复 待解决
HarmonyOS 组件有没有长按事件?
687浏览 • 1回复 待解决
如何去掉div长按的灰色效果
3107浏览 • 1回复 待解决