【发布时间】:2014-11-04 11:40:53
【问题描述】:
如果我们倾斜设备,我正在尝试更改 UILabel 值,因为我正在尝试实现 CMMotionManager 但它对我不起作用,这是我正在使用的代码,
我在 lib 中添加了 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 它不会触发。
任何人都可以帮我解决这个问题或有任何其他方法来处理倾斜设备。
【问题讨论】:
-
我知道了,对于倾斜,我们需要检查 DeviceMotion 及其在 ios 7 中对我有用,但在 ios6 中没有,对此有何评论?
标签: ios accelerometer cmmotionmanager