в моем приложении я хочу вызвать некоторый метод в CCScene myscene в случае поворота устройства (изменение ориентации). Я отключил авторотацию (потому что я хочу, чтобы это не произошло).
Проблема заключается в следующем: я хочу изменить гравитацию в сцене в зависимости от ориентации устройства. Мой код:
-(void) onEnter
{
[super onEnter];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notification_OrientationWillChange:) name:UIApplicationWillChangeStatusBarOrientationNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notification_OrientationDidChange:) name:UIApplicationDidChangeStatusBarOrientationNotification object:nil];
}
-(void) onExit
{
//[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationWillChangeStatusBarOrientationNotification object:nil];
//[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidChangeStatusBarOrientationNotification object:nil];
}
-(void)notification_OrientationWillChange:(NSNotification*)n
{
orientation = (UIInterfaceOrientation)[[n.userInfo objectForKey:UIApplicationStatusBarOrientationUserInfoKey] intValue];
}
-(void)notification_OrientationDidChange:(NSNotification*)n
{
if (orientation == UIInterfaceOrientationLandscapeLeft) {
b2Vec2 gravity( 0, -10);
world->SetGravity(gravity);
}
if (orientation == UIInterfaceOrientationLandscapeRight) {
b2Vec2 gravity( 0, 10);
world->SetGravity(gravity);
}
}
Но в этом случае я могу получать уведомления только в случае активации авторотации (если он отключен, устройство фактически не меняет ориентацию строки состояния) Можете ли вы мне помочь?