harmony 鸿蒙@ohos.deviceStatus.dragInteraction(拖拽)

2023-10-30 浏览 (552)

@ohos.deviceStatus.dragInteraction(拖拽)

拖拽功能模块,提供注册和取消拖拽状态监听的能力。

说明

  • 本模块首批接口从API version 10开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。

  • 本模块接口均为系统接口。

导入模块

import dragInteraction from '@ohos.deviceStatus.dragInteraction'

DragState

拖拽状态。

系统能力:SystemCapability.Msdp.DeviceStatus.Drag

名称说明
MSG_DRAG_STATE_START1表示开始拖拽。
MSG_DRAG_STATE_STOP2表示结束拖拽。
MSG_DRAG_STATE_CANCEL3表示取消拖拽。

示例

enum DragState {
    MSG_DRAG_STATE_START = 1,
    MSG_DRAG_STATE_STOP = 2,
    MSG_DRAG_STATE_CANCEL = 3
}

dragInteraction.on('drag')

on(type: 'drag', callback: Callback<DragState>): void;

注册监听拖拽状态。

系统能力:SystemCapability.Msdp.DeviceStatus.Drag

参数

参数名类型必填说明
typestring监听类型,固定取值为 'drag'
callbackCallback<DragState>回调函数,异步返回拖拽状态消息

示例

try {
  dragInteraction.on('drag', (data : DragState) => {
    console.log(`Drag interaction event: ${JSON.stringify(data)}`);
  });
} catch (error) {
  console.log(`Register failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}

dragInteraction.off('drag')

off(type: 'drag', callback?: Callback<DragState>): void;

取消监听拖拽状态。

系统能力:SystemCapability.Msdp.DeviceStatus.Drag

参数

参数名类型必填说明
typestring监听类型,固定取值为 'drag'
callbackCallback<DragState>需要取消注册的回调函数,若无此参数,则取消当前应用注册的所有回调函数。

示例

// 取消注册单个回调函数
function single_callback(event : DragState) {
  console.log(`Drag interaction event: ${JSON.stringify(event)}`);
  return false;
}
try {
  dragInteraction.on('drag', single_callback);
  dragInteraction.off("drag", single_callback);
} catch (error) {
  console.log(`Execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
// 取消注册所有回调函数
function all_callback(event : DragState) {
  console.log(`Drag interaction event: ${JSON.stringify(event)}`);
  return false;
}
try {
  dragInteraction.on('drag', all_callback);
  dragInteraction.off("drag");
} catch (error) {
  console.log(`Execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}

你可能感兴趣的鸿蒙文章

harmony 鸿蒙接口

harmony 鸿蒙系统公共事件定义(待停用)

harmony 鸿蒙系统公共事件定义

harmony 鸿蒙开发说明

harmony 鸿蒙企业设备管理概述(仅对系统应用开放)

harmony 鸿蒙BundleStatusCallback

harmony 鸿蒙@ohos.bundle.innerBundleManager (innerBundleManager模块)

harmony 鸿蒙@ohos.distributedBundle (分布式包管理)

harmony 鸿蒙@ohos.bundle (Bundle模块)

harmony 鸿蒙@ohos.enterprise.EnterpriseAdminExtensionAbility (企业设备管理扩展能力)

  • 所属分类: 后端技术
  • 本文标签: 鸿蒙 软件
  • 版权声明: 本文链接 https://seaxiang.com/blog/a7bd77f70a734a85a440b748730a2f38