1 回答
TA贡献1806条经验 获得超5个赞
请查看Microsoft 关于 SkiaSharp 的触控操作文章。它使用一个 Effect 来支持触摸操作,更多关于效果的细节在这里:Invoking Events from Effects
基本上,您需要在添加 CanvasView 的容器中添加一个 TouchEffect(或者甚至将效果添加到您的 CanvasView,上面链接的文章中有一个这样的示例):
<Grid BackgroundColor="White" Grid.Row="1">
<skia:SKCanvasView x:Name="canvasView" PaintSurface="OnCanvasViewPaintSurface" />
<Grid.Effects>
<tt:TouchEffect Capture="True" TouchAction="OnTouchEffectAction" />
</Grid.Effects>
</Grid>
然后为 TouchAction 事件添加一个处理程序,如下所示。您需要先将触摸点转换为像素,然后检查是否
void OnTouchEffectAction(object sender, TouchActionEventArgs args)
{
if (args.Type != TouchActionType.Pressed)
{
return;
}
var pointLocation = args.Location;
var point =
new SKPoint((float)(canvasView.CanvasSize.Width * pointLocation.X / canvasView.Width),
(float)(canvasView.CanvasSize.Height * pointLocation.Y / canvasView.Height));
// TODO: Handle your touch here
}
- 1 回答
- 0 关注
- 152 浏览
添加回答
举报