Book Image

iOS Development with Xamarin Cookbook

By : Dimitrios Tavlikos (USD)
Book Image

iOS Development with Xamarin Cookbook

By: Dimitrios Tavlikos (USD)

Overview of this book

Table of Contents (22 chapters)
iOS Development with Xamarin Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Recognizing gestures


In this recipe, we will discuss how to recognize touch gestures and respond accordingly.

Getting ready

Create a new Single View Application in Xamarin Studio and name it GestureApp.

How to do it...

Perform the following steps:

  1. Add a label to the view of the controller.

  2. 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;
      }
    }
  3. Add the following code in the ViewDidLoad method:

    UIPinchGestureRecognizer pinchGesture = new UIPinchGestureRecognizer(this.OnPinchGesture);
    this.View.AddGestureRecognizer(pinchGesture);
  4. Compile and run the app on the simulator. Hold down the option key and click-and-drag the mouse...