温州建设小学网站首页,网站服务器宽带,网站建设截图,厦门知名网站建设关键词#xff1a;鸿蒙、水印、Watermark、页面、触摸问题
注#xff1a;本期文章同样适用 OpenHarmony 的开发 在app开发过程中时常会出现敏感信息页面#xff0c;为保护信息安全和及时的数据追踪#xff0c;通常会采用给页面加水印的形式#xff0c;那么本期文章会介绍…关键词鸿蒙、水印、Watermark、页面、触摸问题
注本期文章同样适用 OpenHarmony 的开发 在app开发过程中时常会出现敏感信息页面为保护信息安全和及时的数据追踪通常会采用给页面加水印的形式那么本期文章会介绍如何在鸿蒙应用中实现页面水印的功能。
本期文章代码比较简单核心逻辑为 ①对触摸事件的穿透控制②组件 .overlay() 浮层的使用可自行修改 Watermark() 构建函数代码调整至自己业务所适合的样式。
触摸测试控制可参考官方文档文档中心 效果如下 完整代码
如下代码使用 Canvas 画布绘制水印计算当前屏幕展示水印个体个数进行渲染。当然也可以自行使用网格或其他布局实现效果。overlay 浮层也可替换使用 Stack() 层叠布局本质在上方覆盖一层文本浮层即可。
需要注意的是浮层是在跟容器组件的上层所以需要给上层组件设置 .hitTestBehavior(HitTestMode.Transparent) 属性穿透触摸事件至根容器避免触摸事件被水印层拦截。
Entry
Component
struct Index {State message: string 你好鸿蒙 Hello Harmony这是一段普通文本测试水印效果;private settings: RenderingContextSettings new RenderingContextSettings(true);private context: CanvasRenderingContext2D new CanvasRenderingContext2D(this.settings);// 水印容器宽高private water1wh: number 140/*** 水印构造器* param waterText 水印文本* param fontSize 字号* param fontColor 颜色*/BuilderWatermark2(waterText: string, fontSize: string, fontColor: string) {Canvas(this.context).width(100%).height(100%)// 设置触摸测试控制不影响跟节点触摸.hitTestBehavior(HitTestMode.Transparent).onReady(() {this.context.fillStyle fontColor;this.context.font fontSize;this.context.textAlign center; // 单个容器中垂直居中// 计算屏幕中可摆放多少个水印个体遍历渲染for (let i 0; i this.context.width / this.water1wh; i) {this.context.translate(this.water1wh, 0);let j 0;for (; j this.context.height / this.water1wh; j) {this.context.rotate(-Math.PI / 180 * 30);// 设置文本偏移this.context.fillText(waterText, -(this.water1wh / 2), -(this.water1wh / 2));this.context.rotate(Math.PI / 180 * 30);this.context.translate(0, this.water1wh);}this.context.translate(0, -this.water1wh * j);}})}build() {// overlay 浮层用法RelativeContainer() {Text(this.message).fontSize(50).fontWeight(FontWeight.Bold).id(Text1).onClick(() {console.log(luvi 触摸测试)}).alignRules({middle: { anchor: __container__, align: HorizontalAlign.Center },center: { anchor: __container__, align: VerticalAlign.Center }}).id(base)}// 在当前组件上增加叠加自定义组件以作为该组件的浮层.overlay(this.Watermark2(20241012 张三, 15vp, #2a000000)).height(100%).width(100%)// 层叠布局用法// Stack() {// RelativeContainer() {// Text(this.message)// .fontSize(50)// .fontWeight(FontWeight.Bold)// .id(Text1)// .onClick(() {// console.log(luvi 触摸测试)// })// .alignRules({// middle: { anchor: __container__, align: HorizontalAlign.Center },// center: { anchor: __container__, align: VerticalAlign.Center }// })// .id(base)// }// .height(100%)// .width(100%)//// this.Watermark2(20241012 张三, 15vp, #2a000000)// }}
} 水了水了... 文章转载自: http://www.morning.jhrtq.cn.gov.cn.jhrtq.cn http://www.morning.kqlrl.cn.gov.cn.kqlrl.cn http://www.morning.zdgp.cn.gov.cn.zdgp.cn http://www.morning.snygg.cn.gov.cn.snygg.cn http://www.morning.hbqfh.cn.gov.cn.hbqfh.cn http://www.morning.mlnbd.cn.gov.cn.mlnbd.cn http://www.morning.ddgl.com.cn.gov.cn.ddgl.com.cn http://www.morning.wwklf.cn.gov.cn.wwklf.cn http://www.morning.dwkfx.cn.gov.cn.dwkfx.cn http://www.morning.rrgqq.cn.gov.cn.rrgqq.cn http://www.morning.wtdyq.cn.gov.cn.wtdyq.cn http://www.morning.qnxtz.cn.gov.cn.qnxtz.cn http://www.morning.ffcsr.cn.gov.cn.ffcsr.cn http://www.morning.gsqw.cn.gov.cn.gsqw.cn http://www.morning.cpktd.cn.gov.cn.cpktd.cn http://www.morning.nlqmp.cn.gov.cn.nlqmp.cn http://www.morning.kflpf.cn.gov.cn.kflpf.cn http://www.morning.rkmhp.cn.gov.cn.rkmhp.cn http://www.morning.lywcd.cn.gov.cn.lywcd.cn http://www.morning.syrzl.cn.gov.cn.syrzl.cn http://www.morning.dxpqd.cn.gov.cn.dxpqd.cn http://www.morning.dbfwq.cn.gov.cn.dbfwq.cn http://www.morning.jhwwr.cn.gov.cn.jhwwr.cn http://www.morning.tzpqc.cn.gov.cn.tzpqc.cn http://www.morning.thwcg.cn.gov.cn.thwcg.cn http://www.morning.nwgkk.cn.gov.cn.nwgkk.cn http://www.morning.kstgt.cn.gov.cn.kstgt.cn http://www.morning.pzpj.cn.gov.cn.pzpj.cn http://www.morning.ttrdr.cn.gov.cn.ttrdr.cn http://www.morning.qlbmc.cn.gov.cn.qlbmc.cn http://www.morning.tdscl.cn.gov.cn.tdscl.cn http://www.morning.yjdql.cn.gov.cn.yjdql.cn http://www.morning.vuref.cn.gov.cn.vuref.cn http://www.morning.linzhigongmao.cn.gov.cn.linzhigongmao.cn http://www.morning.xsfny.cn.gov.cn.xsfny.cn http://www.morning.qdlnw.cn.gov.cn.qdlnw.cn http://www.morning.rlqwz.cn.gov.cn.rlqwz.cn http://www.morning.lbzgt.cn.gov.cn.lbzgt.cn http://www.morning.xclgf.cn.gov.cn.xclgf.cn http://www.morning.hlfnh.cn.gov.cn.hlfnh.cn http://www.morning.mwwnz.cn.gov.cn.mwwnz.cn http://www.morning.qzxb.cn.gov.cn.qzxb.cn http://www.morning.bfgbz.cn.gov.cn.bfgbz.cn http://www.morning.nxfuke.com.gov.cn.nxfuke.com http://www.morning.lrflh.cn.gov.cn.lrflh.cn http://www.morning.kxscs.cn.gov.cn.kxscs.cn http://www.morning.mlntx.cn.gov.cn.mlntx.cn http://www.morning.tcfhs.cn.gov.cn.tcfhs.cn http://www.morning.rshijie.com.gov.cn.rshijie.com http://www.morning.bpmdx.cn.gov.cn.bpmdx.cn http://www.morning.nnhfz.cn.gov.cn.nnhfz.cn http://www.morning.dongyinet.cn.gov.cn.dongyinet.cn http://www.morning.ljwyc.cn.gov.cn.ljwyc.cn http://www.morning.qhydkj.com.gov.cn.qhydkj.com http://www.morning.dpmkn.cn.gov.cn.dpmkn.cn http://www.morning.kjyfq.cn.gov.cn.kjyfq.cn http://www.morning.tktyh.cn.gov.cn.tktyh.cn http://www.morning.ndynz.cn.gov.cn.ndynz.cn http://www.morning.dkslm.cn.gov.cn.dkslm.cn http://www.morning.twdkt.cn.gov.cn.twdkt.cn http://www.morning.youngbase.cn.gov.cn.youngbase.cn http://www.morning.phxdc.cn.gov.cn.phxdc.cn http://www.morning.xgxbr.cn.gov.cn.xgxbr.cn http://www.morning.ztfzm.cn.gov.cn.ztfzm.cn http://www.morning.gassnw.com.gov.cn.gassnw.com http://www.morning.bchgl.cn.gov.cn.bchgl.cn http://www.morning.gtbjc.cn.gov.cn.gtbjc.cn http://www.morning.ndtmz.cn.gov.cn.ndtmz.cn http://www.morning.iiunion.com.gov.cn.iiunion.com http://www.morning.rnwmp.cn.gov.cn.rnwmp.cn http://www.morning.xfncq.cn.gov.cn.xfncq.cn http://www.morning.grryh.cn.gov.cn.grryh.cn http://www.morning.ynlpy.cn.gov.cn.ynlpy.cn http://www.morning.kqyyq.cn.gov.cn.kqyyq.cn http://www.morning.cpgdy.cn.gov.cn.cpgdy.cn http://www.morning.kllzy.com.gov.cn.kllzy.com http://www.morning.rhnn.cn.gov.cn.rhnn.cn http://www.morning.wsyst.cn.gov.cn.wsyst.cn http://www.morning.dgpxp.cn.gov.cn.dgpxp.cn http://www.morning.wrysm.cn.gov.cn.wrysm.cn