HarmonyOS应用开发-ets基础手势LongPressGesture

鸿蒙时代
发布于 2022-1-7 10:40
浏览
0收藏

HarmonyOS应用开发-ets基础手势LongPressGesture-鸿蒙开发者社区
HarmonyOS应用开发-ets基础手势LongPressGesture-鸿蒙开发者社区
3.代码示例

@Entry
@Component
struct Index {
  @State count: number = 0

  build() {
    Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }) {
      Text('LongPress onAction:' + this.count)
      .fontSize(30)
    }
    .height(200).width(300).padding(60).border({ width:1 }).margin(30)
    .gesture(
    LongPressGesture({ repeat: true })
    //长按动作存在会连续触发
      .onAction((event: GestureEvent) => {
        if (event.repeat) { this.count++ }
      })
    //长按动作一结束触发
      .onActionEnd(() => {
        this.count = 0
      })
    )
  }
}

4.效果
长按屏幕效果如图:
HarmonyOS应用开发-ets基础手势LongPressGesture-鸿蒙开发者社区
代码地址:
(https://gitee.com/jltfcloudcn/jump_to/tree/master/JLTF_LongPressGesture)

分类
标签
HarmonyOS应用开发-ets基础手势LongPressGe.docx 40.93K 13次下载
收藏
回复
举报
回复
    相关推荐