GestureDetector 缩放、旋转、拖拽

2020-07-27  本文已影响0人  liboxiang

官方实现用例:https://github.com/flutter/flutter/blob/9d724d4c4483b585dfd4bfd719844802f8b38abe/examples/flutter_gallery/lib/demo/transformations/transformations_demo_gesture_transformable.dart#L503

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: 
    );
上一篇下一篇

猜你喜欢

热点阅读