Skiasharp可以使用以下方法操作触摸事件:
private void OnTouch(object sender, SKTouchEventArgs args)
使用这种方法,我只能处理一个触摸点坐标:
args.Location.X, args.Location.Y
但是如何检测多点触控事件?
例如,Android原生API使您可以管理两个手指位置以检测多点触控。
如何使用SkiaSharp实现这一目标?
答案 0 :(得分:3)
好的,我发现我的问题的解决方案是代码。
//多点触控处理
Dictionary<long, SKPoint> dragDictionary = new Dictionary<long, SKPoint>();
private void OnTouch(object sender, SKTouchEventArgs e)
{
switch (e.ActionType)
{
case SKTouchAction.Pressed:
dragDictionary[e.Id] = e.Location;
break;
case SKTouchAction.Entered:
break;
case SKTouchAction.Moved:
if (dragDictionary.Keys.Count > 1)
{
dragDictionary[e.Id] = e.Location;
SKPoint? p1 = null;
SKPoint? p2 = null;
foreach (long key in dragDictionary.Keys)
{
if (p1 == null)
{
p1 = dragDictionary[key];
}
else if (p2 == null)
{
p2 = dragDictionary[key];
}
}
//MultiTouch handle
}
else
{
//SingleTouch handle
}
break;
case SKTouchAction.Released:
dragDictionary.Remove(e.Id);
break;
case SKTouchAction.Exited:
break;
}
// we have handled these events
e.Handled = true;
((SKCanvasView)sender).InvalidateSurface();
}