GestureDetector 缩放、旋转、拖拽
2020-07-27 本文已影响0人
liboxiang
enum _GestureType {
translate,
scale,
rotate,
}
GestureDetector(
behavior: HitTestBehavior.opaque, // Necessary when translating off screen
///不传onTapUp回调不能实现旋转
onTapUp: (_){
print('onTapUp');
},
onScaleEnd: _onScaleEnd,
onScaleStart: _onScaleStart,
onScaleUpdate: (details) {
if (gestureType == null) {
// Decide which type of gesture this is by comparing the amount of scale
// and rotation in the gesture, if any. Scale starts at 1 and rotation
// starts at 0. Translate will have 0 scale and 0 rotation because it uses
// only one finger.
if ((details.scale - 1).abs() > details.rotation.abs()) {
gestureType = _GestureType.scale;
} else if (details.rotation != 0) {
gestureType = _GestureType.rotate;
} else {
gestureType = _GestureType.translate;
}
print(gestureType);
print('rotate:${details.rotation}');
print('scale:${details.scale}');
}
},
child:
);