iOS:设备方向事件在启动后永远不会到达



我有一个OpenGL游戏,需要知道设备的方向(即纵向与横向)。

API 看起来非常简单...我的视图控制器的相关部分是:

@implementation MyViewController
- (id)init
{
    ...
    // Get orientation events
    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
    [[NSNotificationCenter defaultCenter] addObserver:self
        selector:@selector(didRotate:)
        name:@"UIDeviceOrientationDidChangeNotification" object:nil];
    ...
}
-(void)didRotate:(NSNotification*)notification 
{   
    NSLog(@"didRotate %d", orientation);
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orientation
{
    NSLog(@"shouldAutorotateToInterfaceOrientation %d", orientation);
    return YES;
}
@end

发生的情况是我在启动期间接到一些电话:

shouldAutorotateToInterfaceOrientation 3
shouldAutorotateToInterfaceOrientation 3
shouldAutorotateToInterfaceOrientation 3
shouldAutorotateToInterfaceOrientation 3
didRotate 4
shouldAutorotateToInterfaceOrientation 4
shouldAutorotateToInterfaceOrientation 4
didRotate 1
shouldAutorotateToInterfaceOrientation 1

之后,UIView和EAGLContext被设置,它开始渲染,一切看起来都很棒,但是无论我在玩游戏时旋转手机多少,都应该永远不会再次调用AutorotateToInterfaceOrientation和didRotate。

我可能做错了什么才能发生这种情况?

好吧,这有点尴尬...

原来人像模式锁定已打开。

咚!

最新更新