6
我在想,我只是捕獲開始的UIAcceleration y值,並將其與當前值進行比較,然後'測量',但我不完全知道是否(1)這是正確的(2)這個數學應該是什麼。如何確定設備的角度?
感謝您的任何幫助。
更新:
這是我用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
謝謝,我懂了。在原始問題中附上代碼。 – cynicaljoy 2012-01-02 21:29:33