我正在尝试实现,使两个圆圈同时缩放,但也允许他们被单独拖动。
我已经实现了一些添加圆圈和缩放功能,但拖动功能是我的问题。
我是一个新的使用flutter。
下面是我的代码:
https://github.com/SantyTaco/flutter_app_zoom_example
代码的主要部分如下:
void _handleScaleStart(ScaleStartDetails details) {
setState(() {
_startingFocalPoint = details.focalPoint;
_previousOffset = _offset;
_previousZoom = _zoom;
});
}
void _handleScaleUpdate(ScaleUpdateDetails details) {
setState(() {
_zoom = _previousZoom * details.scale;
// Ensure that item under the focal point stays in the same place despite zooming
final Offset normalizedOffset = (_startingFocalPoint - _previousOffset) / _previousZoom;
_offset = details.focalPoint - normalizedOffset * _zoom;
});
}
@override
Widget build(BuildContext context) {
return Stack(
fit: StackFit.expand,
children: <Widget>[
GestureDetector(
onScaleStart: _scaleEnabled ? _handleScaleStart : null,
onScaleUpdate: _scaleEnabled ? _handleScaleUpdate : null,
child: CustomPaint(
painter: _GesturePainter(
zoom: _zoom,
offset: _offset,
scaleEnabled: _scaleEnabled,
),
child: CustomPaint(
painter: GesturePainter2(
zoom: _zoom,
offset: _offset,
scaleEnabled: _scaleEnabled,
),
)
),
)
]
);
}
}
有人能帮我解决吗?
1条答案
按热度按时间czq61nw11#
请尝试改用localFocalPoint。
希望这个有用。