Я просто хочу получить данные гироскопа с Core Motion с моего iPhone 4, но всегда получаю roll = 0, pitch = 0 и yaw = 0. После интенсивного поиска я узнал, чтоНет гироскопа в iPhone 4?
if (motionManager.isDeviceMotionAvailable)
{
[motionManager startDeviceMotionUpdates];
}
возвращает ложь, хотя я запустить его на 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
Как вы создаете свой 'motionManager'? Можете ли вы опубликовать код? – Saphrosit
Я добавил код, где я инициализирую motionManager ... Может быть, это помогает мне :) – clash