首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法使用ios应用程序实施CMMotionManager

无法使用ios应用程序实施CMMotionManager
EN

Stack Overflow用户
提问于 2014-11-04 19:40:54
回答 1查看 387关注 0票数 0

如果我们倾斜设备,我会尝试更改UILabel的值,为此,我正在尝试实现CMMotionManager,但它对我无效,这就是我正在使用的代码。

我已经在库中添加了CoreMotion。

代码语言:javascript
复制
#import <CoreMotion/CoreMotion.h>

 CMMotionManager *motionManager = [[CMMotionManager alloc] init];
    motionManager.accelerometerUpdateInterval = .2;

    [motionManager startAccelerometerUpdates];

    if ([motionManager isAccelerometerAvailable] == YES)
    {

        NSOperationQueue *queue = [[NSOperationQueue alloc] init];
        [queue setMaxConcurrentOperationCount:1];

        [motionManager startAccelerometerUpdatesToQueue:queue  withHandler:^(CMAccelerometerData *data, NSError *error)
         {

             CMAcceleration acceleration = data.acceleration;


             if(acceleration.y < -0.25) { // tilting the device to the right

                 [self setTextforlabel:@"right"];

             } else if (acceleration.y > 0.25) { // tilting the device to the left

                                  [self setTextforlabel:@"left"];
             }
         }];
    }

这里有什么问题,isAccelerometerAvailable总是假的

startAccelerometerUpdatesToQueue它不会在中启动。

谁能帮我做这个或那里倾斜设备的任何其他方法。

EN

回答 1

Stack Overflow用户

发布于 2014-11-05 15:27:27

你是在设备上运行还是在刺激器中运行加速度计在刺激器中不工作

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26734265

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档