Skip to content

事件处理

触摸事件

typescript
@Component
struct TouchEvents {
  build() {
    Column()
      .onTouch((event: TouchEvent) => {
        if (event.type === TouchType.Down) {
          console.log('Touch Down')
        } else if (event.type === TouchType.Up) {
          console.log('Touch Up')
        }
      })
  }
}

手势事件

typescript
@Component
struct GestureEvents {
  build() {
    Column()
      .gesture(
        TapGesture({ count: 2 })
          .onAction(() => {
            console.log('Double Tap')
          })
      )
  }
}

键盘事件

typescript
@Component
struct KeyEvents {
  build() {
    Column()
      .onKeyEvent((event: KeyEvent) => {
        console.log('Key Code: ' + event.keyCode)
      })
  }
}

最后更新于:

全栈若城