0
我只是想从我的iPhone 4的Core Motion获取一些陀螺仪数据,但总是得到roll = 0,pitch = 0和yaw = 0。 经过密集的搜索我认识到,iPhone 4没有陀螺仪?
if (motionManager.isDeviceMotionAvailable)
{
[motionManager startDeviceMotionUpdates];
}
返回false,虽然我在iPhone 4 我必须能够在设置陀螺仪运行呢?或者我可以做错什么...?
那我减少接口:
@interface GameLayer : CCLayer {
CMMotionManager *motionManager;
}
@property (nonatomic, retain) CMMotionManager *motionManager;
@end
而这正是我实现在MotionManager:
- (id) init
{
self=[super init];
if(self)
{
self.motionManager = [[[CMMotionManager alloc] init] autorelease];
motionManager.deviceMotionUpdateInterval = 1.0/60.0;
if (motionManager.isDeviceMotionAvailable)
{
[motionManager startDeviceMotionUpdates];
}
else
{
NSLog(@"No motion captured");
}
[self scheduleUpdate];
}
return self;
}
,并在那里它被称为循环:
- (void) update:(ccTime)delta
{
CMDeviceMotion *currentDeviceMotion = motionManager.deviceMotion;
motionManager.showsDeviceMovementDisplay = YES;
CMAttitude *currentDeviceAttitude = currentDeviceMotion.attitude;
float roll = currentDeviceAttitude.roll;
float pitch = currentDeviceAttitude.pitch;
float yaw = currentDeviceAttitude.yaw;
}
IT对我有用。检查'motionManager'不是'nil',你确实在设备上运行,而不是在模拟器上运行。 – sch 2012-03-08 20:45:18
你如何创建你的'motionManager'?你能发布代码吗? – Saphrosit 2012-03-08 20:45:55
我添加了一些代码,我初始化了运动管理器...也许这有助于帮助我:) – clash 2012-03-08 22:45:32