鸿蒙5.0开发进阶:API ArkUI框架-ArkTS组件(自定义事件拦截)

HarmonyOS NEXT开发实战:主页瀑布流实现实列 该场景多用于购物、资讯类应用。 阅读详情

往期鸿蒙全套实战文章必看:(文中附带全栈鸿蒙学习资料)


自定义事件拦截

为组件提供自定义的事件拦截能力,开发者可根据事件在控件上按下时发生的位置,输入源等事件信息决定控件上的HitTestMode属性。

说明

从API Version 12开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。

onTouchIntercept

onTouchIntercept(callback: Callback<TouchEvent, HitTestMode>)

元服务API: 从API version 12开始,该接口支持在元服务中使用。

系统能力: SystemCapability.ArkUI.ArkUI.Full

参数:

参数名参数类型必填参数描述
callbackCallback<TouchEvent, HitTestMode>是给组件绑定自定义事件拦截回调,并使能在做触摸测试时回调此函数。

示例

该示例通过onTouchIntercept修改组件的HitTestMode属性。

// xxx.ets
@Entry
@Component
struct Index {
  isPolygon(event: TouchEvent) {
    return true;
  }

  build(){
    Row(){
      Column(){
        Text("hello world")
          .backgroundColor(Color.Blue)
          .fontSize(50)
          .fontWeight(FontWeight.Bold)
          .onClick(()=>{
            console.log("Text click");
          })
      }
      .width(400)
      .height(300)
      .backgroundColor(Color.Pink)
      .onClick(()=>{
        console.log("Column click");
      })
      // 调用onTouchIntercept修改该组件的HitTestMode属性
      .onTouchIntercept((event : TouchEvent) => {
        console.log("OnTouchIntercept + " + JSON.stringify(event));
        if (this.isPolygon(event)) {
          return HitTestMode.None
        }
        return HitTestMode.Default
      })
    }
    .width('100%')
  }
}

鸿蒙开发进阶(HarmonyOS)事件拦截开发指导(C/C++) 多模为应用提供了创建和删除按键、输入事件(鼠标、触摸和轴事件)拦截的能力。使用场景例如:云桌面应用需要拦截按键、鼠标、触摸和轴事件。 阅读详情

相关推荐

鸿蒙NEXT开发:ArkTS组件-通用事件(按键事件)

按键事件指组件与键盘、遥控器等按键设备交互时触发的事件,适用于所有可获焦组件,例如Button。

ZPYQAQ的博客 1235

鸿蒙5.0版开发:ArkTS组件(自定义事件拦截)

为组件提供自定义的事件拦截能力,开发者可根据事件在控件上按下时发生的位置.................

m0_73088370的博客 697

鸿蒙5.0版开发:ArkTS组件-AtomicServiceTabs

AtomicServiceTabs高级组件...........

m0_69424697的博客 1047

鸿蒙next版开发:ArkTS组件自定义事件拦截详解

自定义事件拦截是指开发者可以通过特定的方法来控制事件是否被当前组件处理,或者传递给子组件。在ArkTS中,这通常是通过方法来实现的。实现复杂的交互逻辑:通过控制事件的传递,可以实现复杂的用户界面交互。优化性能:通过减少不必要的事件处理,可以提高应用的性能。提升用户体验:通过精确控制事件的响应,可以提升用户的交互体验。通过本文的介绍,你应该对如何在HarmonyOS 5.0中使用ArkTS实现自定义事件拦截有了基本的了解。

小淼淼的博客 1076

鸿蒙5.0版开发:ArkTS组件-自定义事件拦截

为组件提供自定义的事件拦截能力..........

m0_69424697的博客 401

deap数据集的情绪检测代码环境搭建与实现

deap数据数据集很大

f的博客 4160

鸿蒙点击拦截:onTouchIntercept相关功能使用指南

摘要:鸿蒙系统中的onTouchIntercept API用于拦截触摸事件,在事件传递到子组件前进行处理。通过返回HitTestMode枚举值(Default/Block/Transparent/None)控制事件传递规则,可应用于条件拦截、滑动冲突处理等场景。使用时需注意:1)必须返回枚举值而非布尔值;2)需处理所有TouchType事件类型;3)避免复杂计算;4)优先使用状态管理。典型应用包括动态控制组件交互权限、区分滑动方向等,是处理复杂触摸交互的核心工具。

m0_53077141的博客 503

量化爬虫实战:手把手教你搞定同花顺问财的hexin-v参数(附JS逆向思路与Cookie Hook技巧)

本文详细解析了如何通过JS逆向技术获取同花顺问财平台的`hexin-v`参数,包括Cookie Hook技巧和完整解决方案架构。从环境搭建到参数定位,再到生成逻辑逆向,手把手教你突破数据获取限制,为量化交易提供可靠数据支持。

weixin_42557803的博客 399

【鸿蒙next开发】ArkUI框架:ArkTS组件-按键事件

本文介绍了鸿蒙5.0开发中的按键事件处理,包括onKeyEvent和onKeyPreIme回调的使用方法。

m0_73088370的博客 1189

解决AutoDock与Python版本冲突导致的内存泄漏问题:从BHtree *错误到环境配置优化

本文深入解析了AutoDock分子对接中常见的‘BHtree *’内存泄漏错误,其根源在于SWIG接口模块与Python运行环境的版本不匹配。文章提供了根治方案:通过构建Python 2.5.4与MGLTools 1.5.6的黄金兼容组合,并详细指导环境清理、安装配置及实战测试,从而彻底解决该内存泄漏问题,确保AutoDock工作流的稳定运行。

g5h6i的博客 1116

【低空经济】低空无人机公共测试场与验证基地设计方案

公共测试场与验证基地是为低空无人机相关技术的研发、测试与应用提供一个系统性的平台。在无人机产业蓬勃发展的背景下,建设一个配备完善、功能齐全的公共测试场与验证基地显得尤为重要。该基地不仅可以作为无人机的测试和验证场地,还可以为相关企业、科研机构以及政府部门提供技术支持和服务。因此,为此基地的设计方案必须综合考虑功能性、安全性、灵活性与可持续性等多方面的因素。首先,公共测试场需划分为多个专用区域,以便满足不同类型无人机的测试需求。这包括低空飞行区域、紧急着陆区、操控模拟区和监测与数据采集区等。

2502_92579126的博客 1603

【鸿蒙next开发】ArkUI框架:ArkTS组件-手势拦截增强

本文详细介绍了鸿蒙5.0开发中的手势拦截功能及其相关API的使用。

m0_73088370的博客 1012

JLink版本不兼容?手把手教你解决APM32F003F6P6在Keil中烧写闪退和报错

本文详细解析了APM32F003F6P6在Keil中烧写闪退和报错的解决方案,重点介绍了JLink版本兼容性问题。通过实测不同版本组合,推荐使用JLink 7.20a或6.86b与Keil 5.25的黄金组合,并提供详细的降级驱动和工程配置步骤,帮助开发者高效解决烧写困境。

weixin_33694620的博客 419

鸿蒙5.0开发进阶:API ArkUI框架-ArkTS组件(按键事件)

按键事件指组件与键盘、遥控器等按键设备交互时触发的事件,适用于所有可获焦组件,例如Button。

Androidbye的博客 999

MIC(Maximal Information Coefficient)最大互信息系数

MIC(Maximal Information Coefficient)最大互信息系数是一种用于衡量两个变量之间相关性的统计量。它扩展了传统的互信息(MI)和条件互信息(CMI)的概念,具有更广泛的应用范围。MIC能够捕获包括功能性和非功能性的广泛的关联,具有普遍性和公平性。普遍性意味着在足够的样本量下,MIC能够捕捉到广泛的相关关系,而不仅仅局限于特定的功能类型;公平性则意味着MIC对不同类型的包含同等噪声的关系给出了相似的分数。需要注意的是,虽然MIC具有很多优点,但它也有一些局限性。

qlkaicx的博客 4607

高精度计算Π的值(C语言)

题目要求 限制使用双向链表作存储结构,请根据用户输入的一个整数(该整数表示精确到小数点后的位数,可能要求精确到小数点后500位),高精度计算PI值。可以利用反三角函数幂级展开式来进行计算。 输入5 输出3.14159 思路分析 反三角函数幂级展开式 由公式可以看出,只要计算出来每一个R(n)的值再相加取二倍就可以得到Π的值。 经过推算,要是令R(1)=2,只需要将每个R(n),相加即可。 因...

weixin_46251155的博客 8033

鸿蒙5.0开发进阶:API ArkUI框架-ArkTS组件(Popup控制)

给组件绑定popup弹窗,并设置弹窗内容,交互逻辑和显示状态。

Androidbye的博客 669

Lammps纳米压痕接触面积—Matlab接触面积计算(两种方法)

Lammps纳米压痕接触面积计算

Rockyoung 5449

【鸿蒙next开发】ArkUI框架:ArkTS组件-AtomicServiceTabs

鸿蒙5.0的AtomicServiceTabs组件详解:该高级组件简化了Tabs设计,限制最多5个页签,支持固定样式和位置。

m0_73088370的博客 702

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

鸿蒙5.0开发进阶:API ArkUI框架-ArkTS组件(全屏模态转场)

通过bindContentCover属性为组件绑定全屏模态页面.......

Androidbye的博客 973

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

鸿蒙5.0开发进阶:UI框架-ArkTS组件(RichEditor)

支持图文混排和文本交互式编辑的组件。

Androidbye的博客 1230

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

鸿蒙5.0开发进阶:API ArkUI框架-ArkTS组件(安全区域)

安全区域是指页面的显示区域,默认不与系统设置的非安全区域比如状态栏、导航栏区域重叠,默认情况下开发者开发的界面都被布局在安全区域内。

Androidbye的博客 1274

【鸿蒙next开发】ArkUI框架:ArkTS组件-自定义事件拦截

本文介绍了鸿蒙5.0开发的核心知识点和实战项目,提供了全栈学习资料和最新版应用开发实战学习路线。

m0_73088370的博客 390

【鸿蒙next开发】ArkUI框架:ArkTS组件-全屏模态转场

本文详细介绍了鸿蒙5.0开发中的全屏模态转场技术,重点讲解了bindContentCover属性的使用方法及其参数配置。

m0_73088370的博客 772

鸿蒙5.0开发进阶:ArkTS组件-元服务(AtomicServiceTabs)

AtomicServiceTabs高级组件.........

Androidbye的博客 972

【鸿蒙next开发】ArkUI框架:ArkTS组件-安全区域

本文详细介绍了鸿蒙5.0开发中的安全区域概念及其相关API的使用方法。

m0_73088370的博客 1330
上一篇: 鸿蒙5.0开发进阶:API ArkUI框架-ArkTS组件(自定义事件分发)
下一篇: 鸿蒙5.0开发进阶:API ArkUI框架-ArkTS组件(尺寸设置)
懂你的大海
博客等级 码龄6年 9049粉丝 1381原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值