6
Estoy pensando que solo capturo el valor inicial de UIAcceleration y lo comparo con el valor actual y luego 'measure', pero no sé exactamente si (1) es correcto (2) cuál debería ser esa matemática.¿Cómo puedo determinar el ángulo del dispositivo?
Gracias por cualquier ayuda.
Actualización:
Aquí está el código que utilicé como sugiere jrturton.
#import "ViewController.h"
@interface ViewController()
{
CMMotionManager *motionManager;
}
@end
@implementation ViewController
@synthesize angleLabel;
- (void)startMotion
{
if (motionManager == nil)
{
motionManager = [[CMMotionManager alloc] init];
}
motionManager = [[CMMotionManager alloc] init];
[motionManager startDeviceMotionUpdatesToQueue:[NSOperationQueue currentQueue] withHandler:^(CMDeviceMotion *motion, NSError *error) {
angleLabel.text = [NSString stringWithFormat:@"%g", motion.attitude.pitch];
}];
}
- (void) stopMotion
{
if (motionManager)
{
[motionManager stopDeviceMotionUpdates];
}
motionManager = nil;
}
- (void)viewDidUnload {
[self setAngleLabel:nil];
[super viewDidUnload];
}
@end
Gracias, lo tengo funcionando. Voy a adjuntar el código en la pregunta original. – cynicaljoy