• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# 点击控制
2<!--deprecated_code_no_check-->
3
4设置组件是否可以响应点击事件、触摸事件等手指交互事件。
5
6>  **说明:**
7>
8>  从API version 9开始,该模块不再维护,建议使用[hitTestBehavior](ts-universal-attributes-hit-test-behavior.md)替代。
9>
10>  从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。
11
12
13## 属性
14
15
16| **名称**      | **参数类型** | **描述**                    |
17| ----------- | -------- | ------------------------ |
18| touchable<sup>(deprecated)</sup>   | boolean  | 设置当前组件是否可以响应点击事件、触摸事件等手指交互事件。<br>默认值:true,可以响应交互事件。设置为false时,不可以响应交互事件。 |
19
20## 示例
21
22```ts
23// xxx.ets
24@Entry
25@Component
26struct TouchAbleExample {
27  @State text1: string = ''
28  @State text2: string = ''
29
30  build() {
31    Stack() {
32      Rect()
33        .fill(Color.Gray).width(150).height(150)
34        .onClick(() => {
35          console.info(this.text1 = 'Rect Clicked')
36        })
37        .overlay(this.text1, { align: Alignment.Bottom, offset: { x: 0, y: 20 } })
38      Ellipse()
39        .fill(Color.Pink).width(150).height(80)
40        .touchable(false) // 点击Ellipse区域,不会打印 “Ellipse Clicked”
41        .onClick(() => {
42          console.info(this.text2 = 'Ellipse Clicked')
43        })
44        .overlay(this.text2, { align: Alignment.Bottom, offset: { x: 0, y: 20 } })
45    }.margin(100)
46  }
47}
48```
49
50![zh-cn_image_0000001189624550](figures/zh-cn_image_0000001189624550.gif)
51