Dart 如何使用颤振禁用绘图中的多点触摸
这个问题纯粹基于Dart 如何使用颤振禁用绘图中的多点触摸,dart,flutter,Dart,Flutter,这个问题纯粹基于手势检测器颤振 例如: 在应用程序中,实现了GestureDetector类,因此默认情况下支持多点触控,现在我们需要禁用多点触控,那么最好的方法是什么?。否则,在绘图应用程序中使用gesturedector中的flatter会导致多点触摸问题 那么如何禁用手势检测器中的多点触控?我面临同样的问题,但我通过测量两点之间的距离来解决它 首先,声明两个变量及其值 // These two variables are to save the previous points var f
手势检测器颤振
例如:
在应用程序中,实现了GestureDetector
类,因此默认情况下支持多点触控,现在我们需要禁用多点触控,那么最好的方法是什么?。否则,在绘图应用程序中使用gesturedector
中的flatter
会导致多点触摸问题
那么如何禁用手势检测器中的多点触控?我面临同样的问题,但我通过测量两点之间的距离来解决它
首先,声明两个变量及其值
// These two variables are to save the previous points
var fingerPostionY = 0.0,fingerPostionX = 0.0;
然后在onPanUpdate方法中,我取了两个点来计算它们之间的距离。之后,我做了一个比较,如果距离很大(例如50),那么有很多手指,所以我忽略它,否则屏幕上只有一个手指
onPanUpdate: (details) {
if (fingerPostionY < 1.0){
// assigen for the first time to compare
fingerPostionY = details.globalPosition.dy;
fingerPostionX = details.globalPosition.dx;
}else{
// they use a lot of fingers
double distance = distanceBetweenTwoPoints(details.globalPosition.dx,details.globalPosition.dy,
fingerPostionX,fingerPostionY);
// the distance between two fingers must be above 50
// to disable multi touch
if(distance > 50)
return;
// update to use it in the next comparison
fingerPostionY = details.globalPosition.dy;
fingerPostionX = details.globalPosition.dx;
}
// the code of drawing
setState(() {
RenderBox renderBox = context.findRenderObject();
points.add(TouchPoints(
points: renderBox.globalToLocal(details.globalPosition),
paint: Paint()
..strokeCap = strokeType
..isAntiAlias = true
..color = activeColor.withOpacity(opacity)
..strokeWidth = strokeWidth));
});
},
onPanUpdate:(详细信息){
如果(手指位置<1.0){
//阿西根第一次比较
fingerposition=details.globalPosition.dy;
FingerPositionX=details.globalPosition.dx;
}否则{
//他们用很多手指
双距离=两点之间的距离(details.globalPosition.dx,details.globalPosition.dy,
fingerPostionX、fingerPostionY);
//两个手指之间的距离必须大于50
//禁用多点触摸
如果(距离>50)
返回;
//更新以在下次比较中使用它
fingerposition=details.globalPosition.dy;
FingerPositionX=details.globalPosition.dx;
}
//制图规范
设置状态(){
RenderBox RenderBox=context.findenderobject();
点。添加(接触点)(
要点:renderBox.GlobalTopolocal(详细信息:全局位置),
油漆:油漆()
..strokeCap=strokeType
…Isatarias=真
…color=activeColor.withOpacity(不透明度)
..冲程宽度=冲程宽度);
});
},
重要注意事项:
在onPanEnd方法中,您必须写这一行,因为它
意味着现在手指已经竖起来了
手指位置=0.0
在绘图代码中仍然存在一些尚未解决的性能问题
编辑:
我通过使用路径增强了性能
您可以在GitHub上看到我的代码:
答案可能重复,但与此问题无关。
onPanUpdate: (details) {
if (fingerPostionY < 1.0){
// assigen for the first time to compare
fingerPostionY = details.globalPosition.dy;
fingerPostionX = details.globalPosition.dx;
}else{
// they use a lot of fingers
double distance = distanceBetweenTwoPoints(details.globalPosition.dx,details.globalPosition.dy,
fingerPostionX,fingerPostionY);
// the distance between two fingers must be above 50
// to disable multi touch
if(distance > 50)
return;
// update to use it in the next comparison
fingerPostionY = details.globalPosition.dy;
fingerPostionX = details.globalPosition.dx;
}
// the code of drawing
setState(() {
RenderBox renderBox = context.findRenderObject();
points.add(TouchPoints(
points: renderBox.globalToLocal(details.globalPosition),
paint: Paint()
..strokeCap = strokeType
..isAntiAlias = true
..color = activeColor.withOpacity(opacity)
..strokeWidth = strokeWidth));
});
},