【发布时间】:2012-08-09 15:13:32
【问题描述】:
我开发了一个使用 CoreMotion 获取倾斜信息的小应用程序。
但它不适用于 iPod touch。我在第一台装有 iOS 5.1 的视网膜显示器 iPod touch 上进行了测试。 gyroAvailable 属性返回 YES,所以我假设这个 iPod 确实有一个陀螺仪。
此代码在 iPhone 4 上运行良好:
CMMotionManager *mm = [[CMMotionManager alloc] init];
self.motionManager = mm;
[motionManager setDeviceMotionUpdateInterval:0.05];
CMDeviceMotionHandler motionHandler = ^(CMDeviceMotion *motion, NSError *error) {
[self handleMotion:motion error:error];
};
[motionManager startDeviceMotionUpdatesUsingReferenceFrame:CMAttitudeReferenceFrameXArbitraryCorrectedZVertical toQueue:[NSOperationQueue currentQueue] withHandler:motionHandler];
startDeviceMotionUpdatesUsingReferenceFrame 似乎是罪魁祸首,但我无法从文档中确定此方法不适用于没有陀螺仪的设备。
我所需要的只是用户在纵向模式下向左或向右倾斜设备的精确输出。
我有什么选择?
【问题讨论】:
标签: iphone ios accelerometer ipod-touch core-motion