Iphone 如何注意不推荐使用的快速前进运动?
我想做的是读取加速度,然后做如下操作:Iphone 如何注意不推荐使用的快速前进运动?,iphone,objective-c,ios,accelerometer,motion,Iphone,Objective C,Ios,Accelerometer,Motion,我想做的是读取加速度,然后做如下操作: if (acceleration.y > 0.8) { // Do something } 由于不推荐使用didAccelerate,我想知道如何获得y值: motionManager = [[[CMMotionManager alloc] init] autorelease]; motionManager.accelerometerUpdateInterval = kUpdateInterval; if (motionManager.ac
if (acceleration.y > 0.8) {
// Do something
}
由于不推荐使用didAccelerate,我想知道如何获得y值:
motionManager = [[[CMMotionManager alloc] init] autorelease];
motionManager.accelerometerUpdateInterval = kUpdateInterval;
if (motionManager.accelerometerAvailable) {
[motionManager startAccelerometerUpdates];
}
else {
//this device doesn't have accelerometer notice somewhere??
}
- (void)startAccelerometerUpdates {
// READ Y-VALUE?????
}
我想使用原始加速计数据,这样应用程序也可以在3GS上运行。可以读取Y值吗?编辑:下面的答案不推荐,请检查正确的方法
旧答案: 为此使用UIAccelerator单例实例,例如在AppDelegate中
//in your launching method
UIAccelerometer * accel = [UIAccelerometer sharedAccelerometer];
accel.delegate = self;
//delegate method:
-(void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration{
// use the y-property of the acceleration
}
查看名为“按指定的时间间隔处理运动更新”的搜索部分。在“加速计”子弹中,它说
设置AccelerometrUpdateInterval属性以指定更新间隔。调用StartAccelerMeterUpdatesToQueue:withHandler:方法,传入CMAccelerMeterHandler类型的块。加速计数据作为CMAccelerMeterData对象传递到块中
有一个对CMAcceleration的引用,CMAcceleration是一个保持每轴加速度的结构。是的,你说得对。只是好奇,是什么让你不敢发布关于最新解决方案的信息;)我将编辑我的答案。