Class SKGestureTracker
A high-level gesture handler that recognizes touch gestures and maintains an absolute transform (scale, rotation, and offset).
public sealed class SKGestureTracker : IDisposable
- Inheritance
-
SKGestureTracker
- Implements
- Inherited Members
Remarks
The tracker is the primary public API for gesture handling. It accepts raw touch input via ProcessTouchDown(long, SKPoint, bool), ProcessTouchMove(long, SKPoint, bool), ProcessTouchUp(long, SKPoint), and ProcessMouseWheel(SKPoint, float, float), detects gestures internally, and translates them into transform state changes and higher-level events such as drag lifecycle and fling animation.
Use the Matrix property to apply the current transform when painting. The matrix uses (0,0) as its origin — no view size configuration is required.
All coordinates are in view (screen) space. The tracker converts screen-space deltas to content-space deltas internally when updating Offset.
Basic usage with an SkiaSharp canvas:
var tracker = new SKGestureTracker();
// Forward touch events from your platform:
tracker.ProcessTouchDown(id, new SKPoint(x, y));
tracker.ProcessTouchMove(id, new SKPoint(x, y));
tracker.ProcessTouchUp(id, new SKPoint(x, y));
// In your paint handler:
canvas.Save();
canvas.Concat(tracker.Matrix);
// Draw your content...
canvas.Restore();
// Listen for transform changes to trigger redraws:
tracker.TransformChanged += (s, e) => canvasView.InvalidateSurface();
Constructors
- SKGestureTracker()
Initializes a new instance of the SKGestureTracker class with default options.
- SKGestureTracker(SKGestureTrackerOptions)
Initializes a new instance of the SKGestureTracker class with the specified options.
Properties
- IsDoubleTapEnabled
Gets or sets a value indicating whether double-tap detection is enabled.
- IsDoubleTapZoomEnabled
Gets or sets a value indicating whether double-tap triggers an animated zoom.
- IsEnabled
Gets or sets a value indicating whether gesture detection is enabled.
- IsFlingEnabled
Gets or sets a value indicating whether fling (inertia) animation is enabled after a pan gesture.
- IsFlinging
Gets a value indicating whether a fling (inertia) animation is in progress.
- IsGestureActive
Gets a value indicating whether any gesture is currently active (touch contact in progress).
- IsHoverEnabled
Gets or sets a value indicating whether hover (mouse move without contact) detection is enabled.
- IsLongPressEnabled
Gets or sets a value indicating whether long press detection is enabled.
- IsPanEnabled
Gets or sets a value indicating whether pan gestures update the Offset.
- IsPinchEnabled
Gets or sets a value indicating whether pinch-to-zoom gestures update the Scale.
- IsRotateEnabled
Gets or sets a value indicating whether rotation gestures update the Rotation.
- IsScrollZoomEnabled
Gets or sets a value indicating whether scroll-wheel events trigger zoom.
- IsTapEnabled
Gets or sets a value indicating whether tap detection is enabled.
- IsZoomAnimating
Gets a value indicating whether an animated zoom (from double-tap or ZoomTo(float, SKPoint)) is in progress.
- Matrix
Gets the composite transform matrix that combines scale, rotation, and offset, using (0,0) as the transform origin.
- Offset
Gets the current pan offset in content coordinates.
- Options
Gets the configuration options for this tracker.
- Rotation
Gets the current rotation angle in degrees.
- Scale
Gets the current zoom scale factor.
Methods
- Dispose()
Releases all resources used by this SKGestureTracker instance, including stopping all animations.
- ProcessMouseWheel(SKPoint, float, float)
Processes a mouse wheel (scroll) event.
- ProcessTouchCancel(long)
Processes a touch cancel event.
- ProcessTouchDown(long, SKPoint, bool)
Processes a touch down event.
- ProcessTouchMove(long, SKPoint, bool)
Processes a touch move event.
- ProcessTouchUp(long, SKPoint)
Processes a touch up event.
- Reset()
Resets the tracker to an identity transform (scale 1, rotation 0, offset zero), stops all animations, and raises TransformChanged.
- SetOffset(SKPoint)
Sets the pan offset and raises TransformChanged.
- SetRotation(float, SKPoint?)
Sets the rotation angle and raises TransformChanged.
- SetScale(float, SKPoint?)
Sets the zoom scale, clamping to MinScale/MaxScale, and raises TransformChanged.
- SetTransform(float, float, SKPoint)
Sets the transform to the specified values, clamping scale to MinScale/MaxScale.
- StopFling()
Stops any active fling animation and raises FlingCompleted.
- StopZoomAnimation()
Stops any active zoom animation immediately.
- ZoomTo(float, SKPoint)
Starts an animated zoom by the given multiplicative factor around a focal point.
Events
- DoubleTapDetected
Occurs when a double tap is detected.
- DragEnded
Occurs when a drag operation ends (all touches released).
- DragStarted
Occurs when a drag operation starts (first pan movement after touch down).
- DragUpdated
Occurs on each movement during a drag operation.
- FlingCompleted
Occurs when a fling animation completes (velocity drops below FlingMinVelocity).
- FlingDetected
Occurs when a fling gesture is detected (once, with initial velocity).
- FlingUpdated
Occurs each animation frame during a fling deceleration.
- GestureEnded
Occurs when a gesture interaction ends (last touch released).
- GestureStarted
Occurs when a gesture interaction begins (first touch contact).
- HoverDetected
Occurs when a hover is detected.
- LongPressDetected
Occurs when a long press is detected.
- PanDetected
Occurs when a pan gesture is detected.
- PinchDetected
Occurs when a pinch (scale) gesture is detected.
- RotateDetected
Occurs when a rotation gesture is detected.
- ScrollDetected
Occurs when a scroll (mouse wheel) event is detected.
- TapDetected
Occurs when a single tap is detected.
- TransformChanged
Occurs when the transform state (Scale, Rotation, Offset, or Matrix) changes.