觸摸熱區(qū)設(shè)置
適用于支持通用點(diǎn)擊事件、通用觸摸事件、通用手勢處理的組件。
說明:
開發(fā)前請熟悉鴻蒙開發(fā)指導(dǎo)文檔 :[gitee.com/li-shizhen-skin/harmony-os/blob/master/README.md
]
從API Version 8開始支持。后續(xù)版本如有新增內(nèi)容,則采用上角標(biāo)單獨(dú)標(biāo)記該內(nèi)容的起始版本。
屬性
名稱 | 參數(shù)類型 | 描述 |
---|---|---|
responseRegion | Array<[Rectangle]> | [Rectangle] |
Rectangle對象說明
從API version 9開始,該接口支持在ArkTS卡片中使用。
名稱 | 類型 | 必填 | 描述 |
---|---|---|---|
x | [Length] | 否 | 觸摸點(diǎn)相對于組件左上角的x軸坐標(biāo)。 默認(rèn)值:0vp |
y | [Length] | 否 | 觸摸點(diǎn)相對于組件左上角的y軸坐標(biāo)。 默認(rèn)值:0vp |
width | [Length] | 否 | 觸摸熱區(qū)的寬度。 默認(rèn)值:'100%' |
height | [Length] | 否 | 觸摸熱區(qū)的高度。 默認(rèn)值:'100%'HarmonyOS與OpenHarmony鴻蒙文檔籽料:mau123789是v直接拿 |
說明:
x和y可以設(shè)置正負(fù)值百分比。當(dāng)x設(shè)置為'100%'時表示熱區(qū)往右偏移組件本身寬度大小,當(dāng)x設(shè)置為'-100%'時表示熱區(qū)往左偏移組件本身寬度大小。當(dāng)y設(shè)置為'100%'時表示熱區(qū)往下偏移組件本身高度大小,當(dāng)y設(shè)置為'-100%'時表示熱區(qū)往上偏移組件本身高度大小。
width和height只能設(shè)置正值百分比。width:'100%'表示熱區(qū)寬度設(shè)置為該組件本身的寬度。比如組件本身寬度是100vp,那么'100%'表示熱區(qū)寬度也為100vp。height:'100%'表示熱區(qū)高度設(shè)置為該組件本身的高度。
百分比相對于組件自身寬高進(jìn)行計算。
示例
// xxx.ets
@Entry
@Component
struct TouchTargetExample {
@State text: string = ""
build() {
Column({ space: 20 }) {
Text("{x:0,y:0,width:'50%',height:'100%'}")
// 熱區(qū)寬度為按鈕的一半,點(diǎn)擊右側(cè)無響應(yīng)
Button("button1")
.responseRegion({ x: 0, y: 0, width: '50%', height: '100%' })
.onClick(() = > {
this.text = 'button1 clicked'
})
// 熱區(qū)寬度為按鈕的一半,且右移一個按鈕寬度,點(diǎn)擊button2右側(cè)左邊,點(diǎn)擊事件生效
Text("{x:'100%',y:0,width:'50%',height:'100%'}")
Button("button2")
.responseRegion({ x: '100%', y: 0, width: '50%', height: '100%' })
.onClick(() = > {
this.text = 'button2 clicked'
})
// 熱區(qū)大小為整個按鈕,且下移一個按鈕高度,點(diǎn)擊button3下方按鈕大小區(qū)域,點(diǎn)擊事件生效
Text("{x:0,y:'100%',width:'100%',height:'100%'}")
Button("button3")
.responseRegion({ x: 0, y: '100%', width: '100%', height: '100%' })
.onClick(() = > {
this.text = 'button3 clicked'
})
Text(this.text).margin({ top: 50 })
}.width('100%').margin({ top: 10 })
}
}
審核編輯 黃宇
-
觸摸
+關(guān)注
關(guān)注
7文章
199瀏覽量
64524 -
交互控制
+關(guān)注
關(guān)注
0文章
6瀏覽量
7035 -
鴻蒙
+關(guān)注
關(guān)注
57文章
2395瀏覽量
43085
發(fā)布評論請先 登錄
相關(guān)推薦
HarmonyOS/OpenHarmony應(yīng)用開發(fā)-ArkTS的聲明式開發(fā)范式
鴻蒙ArkTS聲明式開發(fā):跨平臺支持列表【按鍵事件】
![<b class='flag-5'>鴻蒙</b><b class='flag-5'>ArkTS</b><b class='flag-5'>聲明</b><b class='flag-5'>式</b><b class='flag-5'>開發(fā)</b>:<b class='flag-5'>跨</b><b class='flag-5'>平臺</b><b class='flag-5'>支持</b><b class='flag-5'>列表</b>【按鍵事件】](https://file1.elecfans.com/web2/M00/C5/CD/wKgZomYCdwyAIFf5AAB_7E1pFms943.jpg)
鴻蒙ArkTS聲明式開發(fā):跨平臺支持列表【顯隱控制】 通用屬性
![<b class='flag-5'>鴻蒙</b><b class='flag-5'>ArkTS</b><b class='flag-5'>聲明</b><b class='flag-5'>式</b><b class='flag-5'>開發(fā)</b>:<b class='flag-5'>跨</b><b class='flag-5'>平臺</b><b class='flag-5'>支持</b><b class='flag-5'>列表</b>【顯隱<b class='flag-5'>控制</b>】 通用屬性](https://file1.elecfans.com/web2/M00/EB/2D/wKgZomZdZsOAPO5rAACQtOvBUOY300.png)
鴻蒙ArkTS聲明式開發(fā):跨平臺支持列表【禁用控制】 通用屬性
![<b class='flag-5'>鴻蒙</b><b class='flag-5'>ArkTS</b><b class='flag-5'>聲明</b><b class='flag-5'>式</b><b class='flag-5'>開發(fā)</b>:<b class='flag-5'>跨</b><b class='flag-5'>平臺</b><b class='flag-5'>支持</b><b class='flag-5'>列表</b>【禁用<b class='flag-5'>控制</b>】 通用屬性](https://file1.elecfans.com/web2/M00/EC/05/wKgaomZdKOeAQVe2AAB-ihJaxRY734.png)
鴻蒙ArkTS聲明式開發(fā):跨平臺支持列表【形狀裁剪】 通用屬性
![<b class='flag-5'>鴻蒙</b><b class='flag-5'>ArkTS</b><b class='flag-5'>聲明</b><b class='flag-5'>式</b><b class='flag-5'>開發(fā)</b>:<b class='flag-5'>跨</b><b class='flag-5'>平臺</b><b class='flag-5'>支持</b><b class='flag-5'>列表</b>【形狀裁剪】 通用屬性](https://file1.elecfans.com/web2/M00/EB/98/wKgZomZewfuAbiTWAACFRsepasU509.png)
鴻蒙ArkTS聲明式開發(fā):跨平臺支持列表【柵格設(shè)置】 通用屬性
![<b class='flag-5'>鴻蒙</b><b class='flag-5'>ArkTS</b><b class='flag-5'>聲明</b><b class='flag-5'>式</b><b class='flag-5'>開發(fā)</b>:<b class='flag-5'>跨</b><b class='flag-5'>平臺</b><b class='flag-5'>支持</b><b class='flag-5'>列表</b>【柵格<b class='flag-5'>設(shè)置</b>】 通用屬性](https://file1.elecfans.com/web2/M00/EB/93/wKgZomZeuXuAfmJRAADrojiVvnQ389.png)
鴻蒙ArkTS聲明式開發(fā):跨平臺支持列表【菜單控制】 通用屬性
![<b class='flag-5'>鴻蒙</b><b class='flag-5'>ArkTS</b><b class='flag-5'>聲明</b><b class='flag-5'>式</b><b class='flag-5'>開發(fā)</b>:<b class='flag-5'>跨</b><b class='flag-5'>平臺</b><b class='flag-5'>支持</b><b class='flag-5'>列表</b>【菜單<b class='flag-5'>控制</b>】 通用屬性](https://file1.elecfans.com/web2/M00/C6/E9/wKgaomYEK1aAOyTeAADysXFhWs8242.png)
鴻蒙ArkTS聲明式開發(fā):跨平臺支持列表【觸摸測試控制】觸摸交互控制
鴻蒙ArkTS聲明式開發(fā):跨平臺支持列表【全屏模態(tài)轉(zhuǎn)場】模態(tài)轉(zhuǎn)場設(shè)置
![<b class='flag-5'>鴻蒙</b><b class='flag-5'>ArkTS</b><b class='flag-5'>聲明</b><b class='flag-5'>式</b><b class='flag-5'>開發(fā)</b>:<b class='flag-5'>跨</b><b class='flag-5'>平臺</b><b class='flag-5'>支持</b><b class='flag-5'>列表</b>【全屏模態(tài)轉(zhuǎn)場】模態(tài)轉(zhuǎn)場<b class='flag-5'>設(shè)置</b>](https://file1.elecfans.com/web2/M00/EC/ED/wKgZomZpQZCAZW4_AAT2xHmFl1A718.jpg)
鴻蒙ArkTS聲明式開發(fā):跨平臺支持列表【半模態(tài)轉(zhuǎn)場】模態(tài)轉(zhuǎn)場設(shè)置
![<b class='flag-5'>鴻蒙</b><b class='flag-5'>ArkTS</b><b class='flag-5'>聲明</b><b class='flag-5'>式</b><b class='flag-5'>開發(fā)</b>:<b class='flag-5'>跨</b><b class='flag-5'>平臺</b><b class='flag-5'>支持</b><b class='flag-5'>列表</b>【半模態(tài)轉(zhuǎn)場】模態(tài)轉(zhuǎn)場<b class='flag-5'>設(shè)置</b>](https://file1.elecfans.com/web2/M00/EB/93/wKgZomZeuXuAfmJRAADrojiVvnQ389.png)
評論