如果我们倾斜设备,我会尝试更改UILabel的值,为此,我正在尝试实现CMMotionManager,但它对我无效,这就是我正在使用的代码。
我已经在库中添加了CoreMotion。
#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它不会在中启动。
谁能帮我做这个或那里倾斜设备的任何其他方法。
发布于 2014-11-05 15:27:27
你是在设备上运行还是在刺激器中运行加速度计在刺激器中不工作
https://stackoverflow.com/questions/26734265
复制相似问题