點(diǎn)擊控制

2024-01-22 16:31 更新

設(shè)置組件是否可以響應(yīng)點(diǎn)擊事件、觸摸事件等手指交互事件。

說(shuō)明

從API Version 9 開始,該接口廢棄,建議使用hitTestBehavior替代。

從API Version 7開始支持。后續(xù)版本如有新增內(nèi)容,則采用上角標(biāo)單獨(dú)標(biāo)記該內(nèi)容的起始版本。

屬性

名稱

參數(shù)類型

描述

touchable

boolean

設(shè)置當(dāng)前組件是否可以響應(yīng)點(diǎn)擊事件、觸摸事件等手指交互事件。

默認(rèn)值:true

示例

  1. // xxx.ets
  2. @Entry
  3. @Component
  4. struct TouchAbleExample {
  5. @State text1: string = ''
  6. @State text2: string = ''
  7. build() {
  8. Stack() {
  9. Rect()
  10. .fill(Color.Gray).width(150).height(150)
  11. .onClick(() => {
  12. console.info(this.text1 = 'Rect Clicked')
  13. })
  14. .overlay(this.text1, { align: Alignment.Bottom, offset: { x: 0, y: 20 } })
  15. Ellipse()
  16. .fill(Color.Pink).width(150).height(80)
  17. .touchable(false) // 點(diǎn)擊Ellipse區(qū)域,不會(huì)打印 “Ellipse Clicked”
  18. .onClick(() => {
  19. console.info(this.text2 = 'Ellipse Clicked')
  20. })
  21. .overlay(this.text2, { align: Alignment.Bottom, offset: { x: 0, y: 20 } })
  22. }.margin(100)
  23. }
  24. }

以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)