public override void TouchesBegan(NSSet touches, UIEvent evt) { if (evt.TouchesForView(this).Count == 2 && linesInProcess.Count < 1) { bool firstTouch = true; Circle newCircle = new Circle(); string key = ""; foreach (UITouch t in touches) { // Is this a double tap? if (t.TapCount > 1) { this.clearAll(); return; } // Create a circle for the value CGPoint loc = t.LocationInView(this); if (firstTouch) { // Use the touch object (packed in an string, as the key) key = NSValue.ValueFromNonretainedObject(t).ToString(); newCircle.center = loc; firstTouch = false; } else { newCircle.point2 = loc; } } newCircle.setColor(); circlesInProcess.Add(key, newCircle); } else { foreach (UITouch t in touches) { // Is this a double tap? if (t.TapCount > 1) { this.clearAll(); return; } // Use the touch object (packed in an string, as the key) string key = NSValue.ValueFromNonretainedObject(t).ToString(); // Create a line for the value CGPoint loc = t.LocationInView(this); Line newLine = new Line(); newLine.begin = loc; newLine.end = loc; // Put pair in dictionary newLine.setColor(); linesInProcess.Add(key, newLine); } } this.SetNeedsDisplay(); }
public override void TouchesMoved(NSSet touches, UIEvent evt) { if (evt.TouchesForView(this).Count == 2 && linesInProcess.Count < 1) { bool firstTouch = true; Circle circle = null; string key; foreach (UITouch t in touches) { CGPoint loc = t.LocationInView(this); if (firstTouch) { key = NSValue.ValueFromNonretainedObject(t).ToString(); // Find the circle for this touch bool gotCircle = circlesInProcess.TryGetValue(key, out circle); // Update the Circle center if (gotCircle) { circle.center = loc; } firstTouch = false; } else { // Update the circle outside if (circle != null) { circle.point2 = loc; circle.setColor(); } } } } else { foreach (UITouch t in touches) { string key = NSValue.ValueFromNonretainedObject(t).ToString(); // Find the line for this touch Line line; bool gotLine = linesInProcess.TryGetValue(key, out line); // Update the line CGPoint loc = t.LocationInView(this); if (gotLine) { line.end = loc; line.setColor(); Console.WriteLine("beginx = {0}, beginy = {1}, endx = {2}, endy = {3}", line.begin.X, line.begin.Y, line.end.X, line.end.Y); } } } this.SetNeedsDisplay(); }