gpt4 book ai didi

ios - iOS:设备定向事件在启动后永远不会到来

转载 作者:行者123 更新时间:2023-12-01 19:20:37 24 4
gpt4 key购买 nike

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

这些API似乎非常简单... ViewController的相关部分包括:

@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。

我可能会为此做错什么?

最佳答案

好吧,这有点令人尴尬...

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

DOH!

关于ios - iOS:设备定向事件在启动后永远不会到来,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10487659/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com