2017-03-06 55 views
0

您好我想获得IOS acceleration价值没有使用故事板,我的目的是使用该值为计算目的。我不想显示这个值。我用下面的方法,每个人给我的错误:无法使用故事板获得iOS加速值

1)var acceleration: CMAcceleration

2)typedef double UIAccelerationValue;

UIAccelerationValue gravX; 
UIAccelerationValue gravY; 
UIAccelerationValue gravZ; 

没有错误为止,但我不知道如何从这里得到加速。

3)viewcontroller.m:

#import "ViewController.h" 

@interface ViewController() 
@property (nonatomic, strong) CMMotionManager *motionManager; (this gives error if there is no storyboard) 

let manager = CMMotionManager; (this gives error, error if let is replaced by var) 


AccelViewController * __weak weakSelf = self; 
if (manager.accelerometerAvailable) { 
manager.accelerometerUpdateInterval = 0.01f; 
[manager startAccelerometerUpdatesToQueue:[NSOperationQueue  mainQueue] 
          withHandler:^(CMAccelerometerData *data,  NSError *error) { 
    double accelval = data.acceleration.x; 

}]; 

回答

0

你必须在你的项目中添加CoreMotion.framework

Project Target Setting -> General -> Linked Frameworks and Libraries -> Add Core Motion framework. 

和进口框架,你的viewController文件

#import <CoreMotion/CoreMotion.h> 

希望这将删除你的错误。

+0

谢谢,是的这个作品 – jay