使用SKTouchAction.Moved
的ActionType永远不会引发Touch事件,但是会引发SKTouchAction.Pressed
。为什么.Moved
事件永远不会引发?
我正在尝试在SkiaSharp中创建一个滑块。当用户触摸滑块或拖动时,此控件将需要更新 thumb (小的可移动圆圈)。它托管在Xamarin Forms应用程序中,并且我创建了SKCanvasView
来绘制滑块并响应触摸事件。
我已经成功地响应了触摸事件,所以我知道SKCanvasView
正在接收一些UI事件,但是从未引发SKTouchAction.Moved
。
private SKCanvasView CreateSliderControl()
{
var control = new SKCanvasView();
control.PaintSurface += HandlePaintHeightControl;
control.EnableTouchEvents = true;
control.Touch += (sender, args) =>
{
var pt = args.Location;
switch (args.ActionType)
{
case SKTouchAction.Pressed:
// 1. This code gets hit whenever I touch the canvas
control.InvalidateSurface();
break;
case SKTouchAction.Moved:
// 2. This code never gets hit, even if I push, touch, slide, etc
control.InvalidateSurface();
break;
}
};
control.InputTransparent = false;
return control;
}
如上所示,#1
被击中(我可以在此处放置一个断点,并且我的控制面无效)。 #2
永远不会被击中,但是我希望当我将手指滑到控件上时会被击中。
SkiaCanvasView
。 答案 0 :(得分:1)
在SkiaSharp的Github上找到了similar issue。
通过将事件的args中的Handled属性设置为true,尝试告诉OS您要“继续接收触摸事件”。
private SKCanvasView CreateSliderControl()
{
var control = new SKCanvasView();
control.PaintSurface += HandlePaintHeightControl;
control.EnableTouchEvents = true;
control.Touch += (sender, args) =>
{
var pt = args.Location;
switch (args.ActionType)
{
case SKTouchAction.Pressed:
control.InvalidateSurface();
break;
case SKTouchAction.Moved:
control.InvalidateSurface();
break;
}
// Let the OS know that we want to receive more touch events
args.Handled = true;
};
control.InputTransparent = false;
return control;
}