UIKit.UIAccelerometer Class
A class that encapsulates the onboard hardware accelerometer and generates UIKit.UIAcceleration objects.

See Also: UIAccelerometer Members

Syntax

[Foundation.Register("UIAccelerometer", true)]
[ObjCRuntime.Availability(Deprecated=ObjCRuntime.Platform.iOS_5_0, Introduced=ObjCRuntime.Platform.iOS_2_0, Message="Deprecated in iOS 5, use the CoreMotion instead")]
public class UIAccelerometer : Foundation.NSObject

Remarks

The application developer must always use the UIAccelerometer.SharedAccelerometer property to access the onboard accelerometer. Data in the form of UIKit.UIAcceleration objects can then be read via the UIAccelerometer.Acceleration event, which will fire every UIAccelerometer.UpdateInterval seconds.

In the following example, taken from the "GLPaintGameView" sample, the UIAccelerometer.UpdateInterval is set to 1/25th of a second and the OnAcceleration method is assigned to handle acceleration events. In the handler, the UIKit.UIAccelerometerEventArgs parameter is used to determine the specifics of acceleration:

C# Example

      //Configure and enable the accelerometer
			const int AccelerometerFrequency = 25;
			UIAccelerometer.SharedAccelerometer.UpdateInterval = 1.0f / AccelerometerFrequency;
			UIAccelerometer.SharedAccelerometer.Acceleration += OnAccelerated;
          
    private void OnAccelerated (object sender, UIAccelerometerEventArgs e)
		{
#if LINQ
			myAccelerometer = new[]{e.Acceleration.X, e.Acceleration.Y, e.Acceleration.Z}
				.Select((v, i) => v * FilteringFactor + myAccelerometer [i] * (1.0f - FilteringFactor))
				.ToArray ();
#else
			myAccelerometer [0] = e.Acceleration.X * FilteringFactor + myAccelerometer [0] * (1.0 - FilteringFactor);
			myAccelerometer [1] = e.Acceleration.Y * FilteringFactor + myAccelerometer [1] * (1.0 - FilteringFactor);
			myAccelerometer [2] = e.Acceleration.Z * FilteringFactor + myAccelerometer [2] * (1.0 - FilteringFactor);
#endif
          ... etc ...
     }
        

Related content

Requirements

Namespace: UIKit
Assembly: Xamarin.iOS (in Xamarin.iOS.dll)
Assembly Versions: 0.0.0.0