|
| 1 | +# 手势操作 |
| 2 | +> GestureDetector:是一个用于处理用户手势操作的组件,它可以包裹其他组件,并监听用户的点击、滑动、缩放等手势事件。以下是一些 GestureDetector 常用的手势属性和事件处理 |
| 3 | +
|
| 4 | +## GestureDetector类 |
| 5 | +```text |
| 6 | +GestureDetector({ |
| 7 | + super.key, |
| 8 | + this.child, |
| 9 | + this.onTapDown, |
| 10 | + this.onTapUp, |
| 11 | + this.onTap, |
| 12 | + this.onTapCancel, |
| 13 | + this.onSecondaryTap, |
| 14 | + this.onSecondaryTapDown, |
| 15 | + this.onSecondaryTapUp, |
| 16 | + this.onSecondaryTapCancel, |
| 17 | + this.onTertiaryTapDown, |
| 18 | + this.onTertiaryTapUp, |
| 19 | + this.onTertiaryTapCancel, |
| 20 | + this.onDoubleTapDown, |
| 21 | + this.onDoubleTap, |
| 22 | + this.onDoubleTapCancel, |
| 23 | + this.onLongPressDown, |
| 24 | + this.onLongPressCancel, |
| 25 | + this.onLongPress, |
| 26 | + this.onLongPressStart, |
| 27 | + this.onLongPressMoveUpdate, |
| 28 | + this.onLongPressUp, |
| 29 | + this.onLongPressEnd, |
| 30 | + this.onSecondaryLongPressDown, |
| 31 | + this.onSecondaryLongPressCancel, |
| 32 | + this.onSecondaryLongPress, |
| 33 | + this.onSecondaryLongPressStart, |
| 34 | + this.onSecondaryLongPressMoveUpdate, |
| 35 | + this.onSecondaryLongPressUp, |
| 36 | + this.onSecondaryLongPressEnd, |
| 37 | + this.onTertiaryLongPressDown, |
| 38 | + this.onTertiaryLongPressCancel, |
| 39 | + this.onTertiaryLongPress, |
| 40 | + this.onTertiaryLongPressStart, |
| 41 | + this.onTertiaryLongPressMoveUpdate, |
| 42 | + this.onTertiaryLongPressUp, |
| 43 | + this.onTertiaryLongPressEnd, |
| 44 | + this.onVerticalDragDown, |
| 45 | + this.onVerticalDragStart, |
| 46 | + this.onVerticalDragUpdate, |
| 47 | + this.onVerticalDragEnd, |
| 48 | + this.onVerticalDragCancel, |
| 49 | + this.onHorizontalDragDown, |
| 50 | + this.onHorizontalDragStart, |
| 51 | + this.onHorizontalDragUpdate, |
| 52 | + this.onHorizontalDragEnd, |
| 53 | + this.onHorizontalDragCancel, |
| 54 | + this.onForcePressStart, |
| 55 | + this.onForcePressPeak, |
| 56 | + this.onForcePressUpdate, |
| 57 | + this.onForcePressEnd, |
| 58 | + this.onPanDown, |
| 59 | + this.onPanStart, |
| 60 | + this.onPanUpdate, |
| 61 | + this.onPanEnd, |
| 62 | + this.onPanCancel, |
| 63 | + this.onScaleStart, |
| 64 | + this.onScaleUpdate, |
| 65 | + this.onScaleEnd, |
| 66 | + this.behavior, |
| 67 | + this.excludeFromSemantics = false, |
| 68 | + this.dragStartBehavior = DragStartBehavior.start, |
| 69 | + this.trackpadScrollCausesScale = false, |
| 70 | + this.trackpadScrollToScaleFactor = kDefaultTrackpadScrollToScaleFactor, |
| 71 | + this.supportedDevices, |
| 72 | + }) |
| 73 | +``` |
| 74 | + |
| 75 | +### GestureDetector类(...)参数解析 |
| 76 | +| 参数名称 | 使用类型 | 参数介绍 | |
| 77 | +|--------------------------------|-------------------------|----------------------------------------------------| |
| 78 | +| key | Key | 用于接收父类的 key,用于构建 Widget 树的唯一标识 | |
| 79 | +| child | Widget | 被 GestureDetector 包裹的子组件,这是 GestureDetector 所作用的范围 | |
| 80 | +| onTapDown | Function | 当用户按下屏幕时触发的回调函数 | |
| 81 | +| onTapUp | Function | 当用户在屏幕上抬起手指时触发的回调函数 | |
| 82 | +| onTap | Function | 用户轻触屏幕时触发的回调函数 | |
| 83 | +| onTapCancel | Function | 当轻触被取消时触发的回调函数,例如,用户按下后移出 GestureDetector 区域 | |
| 84 | +| onSecondaryTap | Function | 当用户使用第二个手指轻触屏幕时触发的回调函数 | |
| 85 | +| onSecondaryTapDown | Function | 当用户用第二个手指按下屏幕时触发的回调函数 | |
| 86 | +| onSecondaryTapUp | Function | 当用户用第二个手指在屏幕上抬起时触发的回调函数 | |
| 87 | +| onSecondaryTapCancel | Function | 当第二个手指轻触被取消时触发的回调函数 | |
| 88 | +| onTertiaryTapDown | Function | 当用户用第三个手指按下屏幕时触发的回调函数 | |
| 89 | +| onTertiaryTapUp | Function | 当用户用第三个手指在屏幕上抬起时触发的回调函数 | |
| 90 | +| onTertiaryTapCancel | Function | 当第三个手指轻触被取消时触发的回调函数 | |
| 91 | +| onDoubleTapDown | Function | 当用户双击屏幕时触发的回调函数 | |
| 92 | +| onDoubleTap | Function | 当用户双击屏幕时触发的回调函数 | |
| 93 | +| onDoubleTapCancel | Function | 当双击被取消时触发的回调函数 | |
| 94 | +| onLongPressDown | Function | 当用户长按屏幕时触发的回调函数 | |
| 95 | +| onLongPressCancel | Function | 当长按被取消时触发的回调函数 | |
| 96 | +| onLongPress | Function | 当用户长按屏幕一定时间后触发的回调函数 | |
| 97 | +| onLongPressStart | Function | 当长按开始时触发的回调函数 | |
| 98 | +| onLongPressMoveUpdate | Function | 当长按移动时触发的回调函数 | |
| 99 | +| onLongPressUp | Function | 当长按抬起时触发的回调函数 | |
| 100 | +| onLongPressEnd | Function | 当长按结束时触发的回调函数 | |
| 101 | +| onSecondaryLongPressDown | Function | 当用户使用第二个手指长按屏幕时触发的回调函数 | |
| 102 | +| onSecondaryLongPressCancel | Function | 当第二个手指长按被取消时触发的回调函数 | |
| 103 | +| onSecondaryLongPress | Function | 当用户使用第二个手指长按屏幕一定时间后触发的回调函数 | |
| 104 | +| onSecondaryLongPressStart | Function | 当第二个手指长按开始时触发的回调函数 | |
| 105 | +| onSecondaryLongPressMoveUpdate | Function | 当第二个手指长按移动时触发的回调函数 | |
| 106 | +| onSecondaryLongPressUp | Function | 当第二个手指长按抬起时触发的回调函数 | |
| 107 | +| onSecondaryLongPressEnd | Function | 当第二个手指长按结束时触发的回调函数 | |
| 108 | +| onTertiaryLongPressDown | Function | 当用户使用第三个手指长按屏幕时触发的回调函数 | |
| 109 | +| onTertiaryLongPressCancel | Function | 当第三个手指长按被取消时触发的回调函数 | |
| 110 | +| onTertiaryLongPress | Function | 当用户使用第三个手指长按屏幕一定时间后触发的回调函数 | |
| 111 | +| onTertiaryLongPressStart | Function | 当第三个手指长按开始时触发的回调函数 | |
| 112 | +| onTertiaryLongPressMoveUpdate | Function | 当第三个手指长按移动时触发的回调函数 | |
| 113 | +| onTertiaryLongPressUp | Function | 当第三个手指长按抬起时触发的回调函数 | |
| 114 | +| onTertiaryLongPressEnd | Function | 当第三个手指长按结束时触发的回调函数 | |
| 115 | +| onVerticalDragDown | Function | 当用户在垂直方向开始拖动时触发的回调函数 | |
| 116 | +| onVerticalDragStart | Function | 当用户在垂直方向开始拖动时触发的回调函数 | |
| 117 | +| onVerticalDragUpdate | Function | 当用户在垂直方向拖动时触发的回调函数 | |
| 118 | +| onVerticalDragEnd | Function | 当用户在垂直方向拖动结束时触发的回调函数 | |
| 119 | +| onVerticalDragCancel | Function | 当垂直拖动被取消时触发的回调函数 | |
| 120 | +| onHorizontalDragDown | Function | 当用户在水平方向开始拖动时触发的回调函数 | |
| 121 | +| onHorizontalDragStart | Function | 当用户在水平方向开始拖动时触发的回调函数 | |
| 122 | +| onHorizontalDragUpdate | Function | 当用户在水平方向拖动时触发的回调函数 | |
| 123 | +| onHorizontalDragEnd | Function | 当用户在水平方向拖动结束时触发的回调函数 | |
| 124 | +| onHorizontalDragCancel | Function | 当水平拖动被取消时触发的回调函数 | |
| 125 | +| onForcePressStart | Function | 当用户使用力按压屏幕时触发的回调函数 | |
| 126 | +| onForcePressPeak | Function | 当力按压的强度达到峰值时触发的回调函数 | |
| 127 | +| onForcePressUpdate | Function | 当力按压的强度更新时触发的回调函数 | |
| 128 | +| onForcePressEnd | Function | 当力按压结束时触发的回调函数 | |
| 129 | +| onPanDown | Function | 当用户开始拖动(手指接触屏幕)时触发的回调函数 | |
| 130 | +| onPanStart | Function | 当用户开始拖动时触发的回调函数 | |
| 131 | +| onPanUpdate | Function | 当用户拖动时触发的回调函数 | |
| 132 | +| onPanEnd | Function | 当用户拖动结束时触发的回调函数 | |
| 133 | +| onPanCancel | Function | 当拖动被取消时触发的回调函数 | |
| 134 | +| onScaleStart | Function | 当用户开始缩放时触发的回调函数 | |
| 135 | +| onScaleUpdate | Function | 当用户缩放时触发的回调函数 | |
| 136 | +| onScaleEnd | Function | 当用户缩放结束时触发的回调函数 | |
| 137 | +| behavior | HitTestBehavior | 定义了用户如何与 GestureDetector 交互的策略 | |
| 138 | +| excludeFromSemantics | bool | 是否排除此 GestureDetector 从语义树中 | |
| 139 | +| dragStartBehavior | DragStartBehavior | 定义了拖动行为的启动方式 | |
| 140 | +| trackpadScrollCausesScale | bool | 定义了是否使用触摸板滚动触发缩放 | |
| 141 | +| trackpadScrollToScaleFactor | Offset | 触摸板滚动触发缩放的因子 | |
| 142 | +| supportedDevices | Set<PointerDeviceKind> | 一个可选的设备列表,定义了支持 GestureDetector 的设备 | |
0 commit comments