偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

HarmonyOS ArkUI-eTS通用事件監(jiān)聽

系統(tǒng) OpenHarmony
本篇給大家?guī)鞟rkUI-eTS通用事件監(jiān)聽的相關(guān)知識(shí),希望對(duì)你有所幫助!

??想了解更多內(nèi)容,請(qǐng)?jiān)L問:??

??51CTO和華為官方合作共建的鴻蒙技術(shù)社區(qū)??

??https://harmonyos.51cto.com??

1.點(diǎn)擊事件

支持版本: eTS API Version 7+

事件名稱: onClick(callback: (event?: ClickEvent) => void)

ClickEvent對(duì)象:

screenX(點(diǎn)擊點(diǎn)相對(duì)于設(shè)備屏幕左邊沿的X坐標(biāo))

screenY(點(diǎn)擊點(diǎn)相對(duì)于設(shè)備屏幕右邊沿的Y坐標(biāo))

x(點(diǎn)擊點(diǎn)相對(duì)于被點(diǎn)擊元素左邊沿的X坐標(biāo))

y(點(diǎn)擊點(diǎn)相對(duì)于被點(diǎn)擊元素上邊沿的Y坐標(biāo))

timestamp(事件時(shí)間戳)

target(API Version 8+ 支持此屬性)/類型:EventTarget

使用示例:

@Entry
@Component
struct Sample {
@State text: string = ''
build() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Button('點(diǎn)擊按鈕').backgroundColor(Color.Blue).width('50%').height(50)
.onClick((event: ClickEvent) => {
console.info(this.text = '點(diǎn)擊點(diǎn)相對(duì)于屏幕位置:' + '\n 相對(duì)于屏幕左邊X:' + event.screenX + '\n 相對(duì)于屏幕頂部Y:' + event.screenY
+ '\n所點(diǎn)擊按鈕:' + '\n 點(diǎn)擊點(diǎn)相對(duì)于父元素坐標(biāo):\n (x:'
+ event.target.area.globalPos.x + ',y:' + event.target.area.globalPos.y + ')\n 所點(diǎn)擊按鈕寬度:'
+ event.target.area.width + '\n 所點(diǎn)擊按鈕高度:' + event.target.area.height)
})
Text(this.text).fontSize(15).padding(15)
}
.width('100%')
.height('100%')
}
}

效果演示:

2.觸摸事件

支持版本: eTS API Version 7+

事件名稱: onTouch(callback: (event?: TouchEvent) => void)

TouchEvent對(duì)象:

type(觸摸事件的類型) / 類型:TouchType

–>TouchType.Down(手指按下時(shí)觸發(fā))

–>TouchType.Up(手指抬起時(shí)觸發(fā))

–>TouchType.Move(手指按壓在屏幕上移動(dòng)時(shí)觸發(fā))

–>TouchType.Cancel(觸摸事件取消時(shí)觸發(fā))

touches(全部手指信息)

changedTouches(當(dāng)前發(fā)生變化的手指信息)

timestamp(事件時(shí)間戳)

target(被觸摸元素對(duì)象)–>此屬性可參考上方點(diǎn)擊事件中表格參數(shù)

使用示例:

@Entry
@Component
struct Sample {
@State text: string = ''
@State eventType: string=''
build() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Button('觸摸按鈕').backgroundColor(Color.Blue).width('70%').height(60)
.onTouch((event:TouchEvent)=>{
if(event.type == TouchType.Down){
this.eventType = '按下'
}
if(event.type == TouchType.Up){
this.eventType = '抬起'
}
if(event.type == TouchType.Move){
this.eventType = '按下移動(dòng)'
}
console.info(this.text = '觸摸類型:' + this.eventType)
})
Text(this.text).fontSize(15).padding(15)
}
.width('100%')
.height('100%')
}
}

效果演示:

3.掛載卸載事件

支持版本: eTS API Version 7+

事件名稱:

1.onAppear(callback: () => void)

2.onDisappear(callback: () => void)

關(guān)鍵操作: import prompt from ‘@system.prompt’

注意事項(xiàng): 因需要讀取設(shè)備系統(tǒng)信息,運(yùn)行需要在模擬真機(jī)或真機(jī)運(yùn)行

使用示例:

import prompt from '@system.prompt';
@Entry
@Component
struct Sample {
private text: string = '掛載文本'
@State isShow: boolean = true
private changeAppear: string = '隱藏文本'
build() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Button(this.changeAppear)
.backgroundColor(Color.Blue)
.width(100)
.height(60)
.onClick(() => {
this.isShow = !this.isShow
})
if (this.isShow) {
Text(this.text)
.fontSize(20)
//掛載
.onAppear(() => {
this.changeAppear = '顯示文本'
prompt.showToast({ message: '文本顯示', duration: 2000 })
})
//卸載
.onDisAppear(() => {
this.changeAppear = '隱藏文本'
prompt.showToast({ message: '文本隱藏', duration: 2000 })
})
}
}
.width('100%')
.height('100%')
}
}

效果演示:

4.按鍵事件

支持版本: eTS API Version 7+

事件名稱: onKeyEvent(event: (event?: KeyEvent) => void)

KeyEvent對(duì)象:

type(按鍵事件的類型) / 類型:KeyType

–>TouchType.Down(按下按鍵)

–>TouchType.Up(松開按鍵)

KeySource(觸發(fā)當(dāng)前按鍵的輸入設(shè)備類型) / 類型:KeySource

–>KeySource.Unknown(輸入設(shè)備類型未知)

–>KeySource.Keyboard(輸入設(shè)備類型為鍵盤)

KeyCode(按鍵的鍵碼)

注意事項(xiàng): 因需要讀取設(shè)備系統(tǒng)信息,運(yùn)行需要在模擬真機(jī)或真機(jī)運(yùn)行

使用示例:

@Entry
@Component
struct Sample {
@State text: string = ''
@State eventType: string = ''
build() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Button('按鍵')
.backgroundColor(Color.Blue)
.width(100)
.height(60)
.onKeyEvent((event: KeyEvent) => {
if (event.type === KeyType.Down) {
this.eventType = '按下'
}
if (event.type === KeyType.Up) {
this.eventType = '松開'
}
console.info(this.text = '按鍵類型:' + this.eventType + '\n鍵碼:' + event.keyCode + '\n鍵值:' + event.keyText)
})
Text(this.text).fontSize(15)
}
.width('100%')
.height('100%')
}
}

效果演示:

??想了解更多內(nèi)容,請(qǐng)?jiān)L問:??

??51CTO和華為官方合作共建的鴻蒙技術(shù)社區(qū)??

??https://harmonyos.51cto.com??

責(zé)任編輯:jianghua 來源: 鴻蒙社區(qū)
相關(guān)推薦

2022-02-23 15:07:22

HarmonyOS常用控制ArkUI-eTS

2022-07-05 16:13:37

ArkUI-eTS智能晾曬系統(tǒng)

2022-10-24 14:49:54

ArkUI心電圖組件

2022-11-02 16:06:54

ArkUIETS

2022-07-04 16:34:46

流光按鈕Stack

2021-11-26 10:08:57

鴻蒙HarmonyOS應(yīng)用

2022-07-11 16:26:37

eTS計(jì)算鴻蒙

2022-05-26 14:50:15

ArkUITS擴(kuò)展

2021-11-19 09:48:33

鴻蒙HarmonyOS應(yīng)用

2011-11-21 16:49:58

日志常用事件

2022-09-05 15:22:27

ArkUIets

2022-07-07 14:01:59

管家服務(wù)系統(tǒng)ArkUI eTS

2023-04-09 14:48:03

JavaScript腳本語言開發(fā)

2022-01-25 17:05:44

ArkUI_eTS操作系統(tǒng)鴻蒙

2022-09-16 15:34:32

CanvasArkUI

2009-09-03 17:59:18

C#調(diào)用事件

2023-03-13 15:03:05

鴻蒙ArkUI

2022-08-12 19:13:07

etswifi連接操作

2022-05-10 10:53:55

日志組件鴻蒙

2021-12-23 09:00:00

架構(gòu)微服務(wù)數(shù)據(jù)
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)