public override void TouchesEnded(NSSet touches, UIEvent evt) { base.TouchesEnded(touches, evt); foreach (UITouch touch in touches.Cast <UITouch>()) { // Get polyline from dictionary and remove it from dictionary FingerPaintPolyline polyline = inProgressPolylines[touch.Handle]; inProgressPolylines.Remove(touch.Handle); // Add final point to path and save with completed polylines polyline.Path.AddLineToPoint(touch.LocationInView(this)); completedPolylines.Add(polyline); } SetNeedsDisplay(); }
public override void TouchesBegan(NSSet touches, UIEvent evt) { base.TouchesBegan(touches, evt); foreach (UITouch touch in touches.Cast <UITouch>()) { // Create a FingerPaintPolyline, set the initial point, and store it FingerPaintPolyline polyline = new FingerPaintPolyline { Color = StrokeColor, StrokeWidth = StrokeWidth, }; polyline.Path.MoveToPoint(touch.LocationInView(this)); inProgressPolylines.Add(touch.Handle, polyline); } SetNeedsDisplay(); }
// Overrides public override bool OnTouchEvent(MotionEvent args) { // Get the pointer index int pointerIndex = args.ActionIndex; // Get the id to identify a finger over the course of its progress int id = args.GetPointerId(pointerIndex); // Use ActionMasked here rather than Action to reduce the number of possibilities switch (args.ActionMasked) { case MotionEventActions.Down: case MotionEventActions.PointerDown: // Create a Polyline, set the initial point, and store it FingerPaintPolyline polyline = new FingerPaintPolyline { Color = StrokeColor, StrokeWidth = StrokeWidth }; polyline.Path.MoveTo(args.GetX(pointerIndex), args.GetY(pointerIndex)); inProgressPolylines.Add(id, polyline); break; case MotionEventActions.Move: // Multiple Move events are bundled, so handle them differently for (pointerIndex = 0; pointerIndex < args.PointerCount; pointerIndex++) { id = args.GetPointerId(pointerIndex); inProgressPolylines[id].Path.LineTo(args.GetX(pointerIndex), args.GetY(pointerIndex)); } break; case MotionEventActions.Up: case MotionEventActions.Pointer1Up: inProgressPolylines[id].Path.LineTo(args.GetX(pointerIndex), args.GetY(pointerIndex)); // Transfer the in-progress polyline to a completed polyline completedPolylines.Add(inProgressPolylines[id]); inProgressPolylines.Remove(id); break; case MotionEventActions.Cancel: inProgressPolylines.Remove(id); break; } // Invalidate to update the view Invalidate(); // Request continued touch input return(true); }