/// <summary> /// CREATE GESTURE RECOGNIZERS FOR DRAG/DROP AND LONG PRESS /// </summary> void AddSensorGestures(sensor Sensor, UIView mainView) { ////CREATE OFFSETS TO FOLLOW EACH SUBVIEW AS IT MOVES nfloat dx = 0; nfloat dy = 0; Sensor.panGesture = new UIPanGestureRecognizer(() => { if (Sensor.panGesture.State == UIGestureRecognizerState.Began) { //View.BringSubviewToFront(Sensor.snapArea); mainView.BringSubviewToFront(Sensor.snapArea); } if ((Sensor.panGesture.State == UIGestureRecognizerState.Began || Sensor.panGesture.State == UIGestureRecognizerState.Changed) && (Sensor.panGesture.NumberOfTouches == 1)) { // remove any previosuly applied snap behavior to avoid a flicker that will occur if both the gesture and physics are operating on the view simultaneously if (snap != null) { animator.RemoveBehavior(snap); } //var p0 = Sensor.panGesture.LocationInView (View); var p0 = Sensor.panGesture.LocationInView(mainView); if (dx == 0) { dx = p0.X - Sensor.snapArea.Center.X; } if (dy == 0) { dy = p0.Y - Sensor.snapArea.Center.Y; } // this is where the offsets are applied so that the location of the image follows the point where the image is touched as it is dragged, // otherwise the center of the image would snap to the touch point at the start of the pan gesture var p1 = new CGPoint(p0.X - dx, p0.Y - dy); Sensor.snapArea.Center = p1; } else if (Sensor.panGesture.State == UIGestureRecognizerState.Ended) { //View.SendSubviewToBack(Sensor.snapArea); mainView.SendSubviewToBack(Sensor.snapArea); // reset offsets when dragging ends so that they will be recalculated for next touch and drag that occurs dx = 0; dy = 0; /// CHECK IF SENSOR WAS DROPPED IN LOW OR HIGH SECTION AnalyserUtilities.updateLowHighArea(Sensor.panGesture.LocationInView(mainView), Sensor, lowHighSensors, this, mainView); ////FIGURE OUT WHERE TO SNAP THE SUBVIEW BASED ON IT'S LOCATION AND IDENTIFIER AnalyserUtilities.LHSwapCheck(this, lowHighSensors, Convert.ToInt32(Sensor.snapArea.AccessibilityIdentifier), Sensor.panGesture.LocationInView(mainView), mainView); } else if (Sensor.panGesture.State == UIGestureRecognizerState.Failed) { Console.WriteLine("Touch has failed to be recognized for " + Sensor.snapArea.AccessibilityIdentifier + " area"); } }); Sensor.holdGesture = new UILongPressGestureRecognizer(() => { if (Sensor.holdGesture.State == UIGestureRecognizerState.Began) { } }); }