2011-12-31 17 views
6

मुझे लगता है कि मैं केवल शुरुआती यूआईसीक्लेरेशन वाई मान को कैप्चर करता हूं और इसे वर्तमान मान से तुलना करता हूं और फिर 'माप' करता हूं लेकिन मुझे बिल्कुल नहीं पता कि (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 

उत्तर

4

इससे भी आसान है। CMDeviceMotion की attitude संपत्ति का उपयोग करें। दस्तावेज के लिए here देखें।

+0

धन्यवाद, मुझे यह काम मिल गया। मूल प्रश्न में कोड संलग्न करने के लिए जा रहे हैं। – cynicaljoy

संबंधित मुद्दे