iPhone 4S のピッチ、ロール、ヨーを記録する簡単なコードを作成しようとしています。タイマーは正しく起動していますが、ピッチ、ロール、ヨーの値は常にコンソールに 0.0000000 として表示されます。ここで何が欠けていますか?どんな助けでも大歓迎です!
ここに私の.hファイルがあります:
@interface ViewController : UIViewController
@property (nonatomic, retain) CMMotionManager *motionManager;
@property(readonly, weak) CMDeviceMotion *deviceMotion;
-(void)doSomething;
@end
そして、ここに私の.mファイルがあります:
#import "ViewController.h"
@implementation ViewController
@synthesize motionManager = _motionManager;
@synthesize deviceMotion = _deviceMotion;
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[_motionManager startDeviceMotionUpdates];
[NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(doSomething) userInfo:nil repeats:YES];
}
- (void)doSomething
{
NSLog(@"Reading Device Motion Updates..");
_deviceMotion = [_motionManager deviceMotion];
NSLog(@"Roll = %f, Pitch = %f, Yaw = %f", _deviceMotion.attitude.roll, _deviceMotion.attitude.pitch, _deviceMotion.attitude.yaw);
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
[_motionManager stopDeviceMotionUpdates];
}
@end