![](/img/trans.png)
[英]How to load file .svg with SkiaSharp on Xamarin forms?
[英]Add tap events to elements inside an SVG using SkiaSharp in Xamarin.Forms
我想得到svg里面的特定点为xamarin.forms 请问有什么方法可以实现吗?
提前致谢。
回答这个老问题可能会帮助像我这样的未来探索者——在我的应用程序中,我使用了 SkiaSharp 自己的位于SKCanvas
上的点击处理程序。 您使用EnableTouchEvents
属性打开它们,然后在Touch
属性中设置回调。 此外,在回调处理程序中确保设置e.Handled = true;
在SKTouchEventArgs
上,否则您将无法获得完整的SKTouchAction
类型。 水龙头位置也包括在内。
是的,您可以使用Skiasharp将触摸事件添加到特定点。 您只需要按位置过滤操作即可。 假设您正在使用Xaml和C#,则Xaml代码将如下所示
<Grid BackgroundColor="White"
Grid.Row="1">
<skia:SKCanvasView x:Name="canvasView"
PaintSurface="OnCanvasViewPaintSurface" />
<Grid.Effects>
<tt:TouchEffect Capture="True"
TouchAction="OnTouchEffectAction" />
</Grid.Effects>
</Grid>
然后您的C#会像这样
void OnTouchEffectAction(object sender, TouchActionEventArgs args)
{
// Convert Xamarin.Forms point to pixels
Point pt = args.Location;
SKPoint point =
new SKPoint((float)(canvasView.CanvasSize.Width * pt.X / canvasView.Width),
(float)(canvasView.CanvasSize.Height * pt.Y / canvasView.Height));
// Uncomment the code below based on what you specifically need
// if (point != The Point you care about) or (pt != The Location you care about
// return;
switch (args.Type)
{
case TouchActionType.Pressed:
if (bitmap.HitTest(point))
{
touchIds.Add(args.Id);
bitmap.ProcessTouchEvent(args.Id, args.Type, point);
break;
}
break;
case TouchActionType.Moved:
if (touchIds.Contains(args.Id))
{
bitmap.ProcessTouchEvent(args.Id, args.Type, point);
canvasView.InvalidateSurface();
}
break;
case TouchActionType.Released:
case TouchActionType.Cancelled:
if (touchIds.Contains(args.Id))
{
bitmap.ProcessTouchEvent(args.Id, args.Type, point);
touchIds.Remove(args.Id);
canvasView.InvalidateSurface();
}
break;
}
}
Charles Petzold与Skiasharp一起撰写了这些Github示例 ,请查看它们以获取更好的主意
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.