美文网首页
GestureDetector 缩放、旋转、拖拽

GestureDetector 缩放、旋转、拖拽

作者: liboxiang | 来源:发表于2020-07-27 08:55 被阅读0次

    官方实现用例: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: 
        );
    

    相关文章

      网友评论

          本文标题:GestureDetector 缩放、旋转、拖拽

          本文链接:https://www.haomeiwen.com/subject/ilclkktx.html