![](/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.