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

Handling motion events


In this recipe, we will learn how to intercept and respond to shake gestures.

Getting ready

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

How to do it...

Perform the following steps:

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

  2. Enter the following code in the MotionEventsAppViewController class:

    public override bool CanBecomeFirstResponder
    {
      get {  return true; }
    }
    public override void ViewDidAppear (bool animated)
    {
      base.ViewDidAppear (animated);
      this.BecomeFirstResponder();
    }
    public override void MotionBegan (UIEventSubtype motion, UIEvent evt)
    {
      base.MotionBegan (motion, evt);
      this.lblOutput.Text = "Motion started!";
    }
    public override void MotionEnded (UIEventSubtype motion, UIEvent evt)
    {
      base.MotionEnded (motion, evt);
      this.lblOutput.Text = "Motion ended!";
    }
    public override void MotionCancelled (UIEventSubtype motion, UIEvent evt)
    {
      base.MotionCancelled (motion, evt);
      this.lblOutput.Text = "Motion cancelled!";
    }
  3. Compile...