UIAccelerometer Class
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
A class that encapsulates the onboard hardware accelerometer and generates UIAcceleration objects.
[Foundation.Register("UIAccelerometer", true)]
public class UIAccelerometer : Foundation.NSObject
[<Foundation.Register("UIAccelerometer", true)>]
type UIAccelerometer = class
inherit NSObject
- Inheritance
- Attributes
Remarks
The application developer must always use the SharedAccelerometer property to access the onboard accelerometer. Data in the form of UIAcceleration objects can then be read via the Acceleration event, which will fire every UpdateInterval seconds.
In the following example, taken from the "GLPaintGameView" sample, the UpdateInterval is set to 1/25th of a second and the OnAcceleration method is assigned to handle acceleration events. In the handler, the UIAccelerometerEventArgs parameter is used to determine the specifics of acceleration:
//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 ...
}
Constructors
| Name | Description |
|---|---|
| UIAccelerometer() |
Creates a new UIAccelerometer with default values. |
| UIAccelerometer(NativeHandle) |
A constructor used when creating managed representations of unmanaged objects. Called by the runtime. |
| UIAccelerometer(NSObjectFlag) |
Constructor to call on derived classes to skip initialization and merely allocate the object. |
Properties
| Name | Description |
|---|---|
| AccessibilityAttributedUserInputLabels | (Inherited from NSObject) |
| AccessibilityRespondsToUserInteraction | (Inherited from NSObject) |
| AccessibilityTextualContext | (Inherited from NSObject) |
| AccessibilityUserInputLabels | (Inherited from NSObject) |
| Class | (Inherited from NSObject) |
| ClassHandle |
The Objective-C class handle for this class. |
| DebugDescription | (Inherited from NSObject) |
| Delegate |
An instance of the UIKit.IUIAccelerometerDelegate model class which acts as the class delegate. |
| Description | (Inherited from NSObject) |
| Handle |
Handle (pointer) to the unmanaged object representation. (Inherited from NSObject) |
| IsDirectBinding | (Inherited from NSObject) |
| IsProxy | (Inherited from NSObject) |
| RetainCount | (Inherited from NSObject) |
| Self | (Inherited from NSObject) |
| SharedAccelerometer | |
| Superclass | (Inherited from NSObject) |
| SuperHandle |
Handle used to represent the methods in the base class for this NSObject. (Inherited from NSObject) |
| UpdateInterval | |
| WeakDelegate | |
| Zone | (Inherited from NSObject) |
Methods
Events
| Name | Description |
|---|---|
| Acceleration |
This event is raised when a new acceleration event is ready. |