In this recipe, we will discuss how to recognize touch gestures and respond accordingly.
Perform the following steps:
Add a label to the view of the controller.
Add the following method in the
GestureAppViewController
class:private void OnPinchGesture(UIPinchGestureRecognizer pinch) { switch (pinch.State) { case UIGestureRecognizerState.Began: this.lblOutput.Text = "Pinch began!"; break; case UIGestureRecognizerState.Changed: this.lblOutput.Text = "Pinch changed!"; break; case UIGestureRecognizerState.Ended: this.lblOutput.Text = "Pinch ended!"; break; } }
Add the following code in the
ViewDidLoad
method:UIPinchGestureRecognizer pinchGesture = new UIPinchGestureRecognizer(this.OnPinchGesture); this.View.AddGestureRecognizer(pinchGesture);
Compile and run the app on the simulator. Hold down the option key and click-and-drag the mouse...