In this recipe, we will learn how to receive the accelerometer events to create an app that is aware of the device movement.
Create a new Single View Application in Xamarin Studio and name it AccelerometerApp
.
Perform the following steps:
Add two buttons and a label on the view of the controller.
In the
ViewDidLoad
method, add the following code:this.btnStop.Enabled = false; UIAccelerometer.SharedAccelerometer.UpdateInterval = 1 / 10; this.btnStart.TouchUpInside += delegate { this.btnStart.Enabled = false; UIAccelerometer.SharedAccelerometer.Acceleration += this.Acceleration_Received; this.btnStop.Enabled = true; } ; this.btnStop.TouchUpInside += delegate { this.btnStop.Enabled = false; UIAccelerometer.SharedAccelerometer.Acceleration -= this.Acceleration_Received; this.btnStart.Enabled = true; } ;
Add the...