代码之家  ›  专栏  ›  技术社区  ›  Nilesh soni

颤振图像已缩放,但如何更改缩放位置

  •  -1
  • Nilesh soni  · 技术社区  · 2 年前

    您好,我已经实现了双击以在Flatter应用程序上进行缩放,但当图像被缩放时,当它处于缩放位置时,我无法导航到图像的其他部分。 捏到缩放效果很好, 双击可缩放并重置为正常状态,也可以正常工作。 唯一的问题是在图像处于缩放状态时无法在图像中移动。 请帮助我这是我的代码:

    GestureDetector(
                onDoubleTapDown: (details) {
                  tapDownDetails = details;
                },
                onDoubleTap: () {
                  final position = tapDownDetails?.localPosition;
                  final double scale = 4;
    
                  final x = -position!.dx * (scale - 1);
                  final y = -position.dy * (scale - 1);
    
                  final zoomed = Matrix4.identity()
                    ..translate(x, y)
                    ..scale(scale);
    
                  final end = _controller!.value.isIdentity()
                      ? zoomed
                      : Matrix4.identity();
    
                  _animation = Matrix4Tween(
                    begin: _controller?.value,
                    end: end,
                  ).animate(
                    CurveTween(curve: Curves.easeInOut)
                        .animate(_animationController!),
                    // CurvedAnimation(parent: _animationController!, curve: Curves.easeInOut),
                  );
                  _animationController?.forward(from: 0);
                },
                child: InteractiveViewer(
                  transformationController: _controller,
                  clipBehavior: Clip.none,
                  panEnabled: false,
                  minScale: minScale,
                  maxScale: maxScale,
                  onInteractionStart: (details) {
                    if (details.pointerCount < 2) return;
                    if (entry == null) {
                      showOverlay(context);
                    }
                  },
                  onInteractionUpdate: (details) {
                    if (entry == null) return;
                    this.scale = details.scale;
                    entry!.markNeedsBuild();
                  },
                  onInteractionEnd: (details) {
                    if (details.pointerCount != 1) return;
                    resetAnimation();
                  },
                  child: Image(
                    image: imageProvider,
                  ),
                ),
              ),
    
    1 回复  |  直到 2 年前
        1
  •  1
  •   Peter Koltai    2 年前

    删除此行或设置为 true ,这是默认值。这将启用平移。

    panEnabled: true,