我正在开发 iPhone 游戏,我很想知道当设备强制游戏自动旋转时是否有回调函数被调用,以便我可以更改 HUD 元素。
或者我运行无限循环来检查应用程序是否已在不同的线程中旋转?问题是我不认为这是一个有效的方法。大家有什么好的解决办法吗?
最佳答案
您所要做的就是:
在你的didfinishlaunching
中写下这个
[[UIDevice currentDevice] beginGenerateDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self 选择器:@selector(didRotate:)
名称:UIDeviceOrientationDidChangeNotification 对象:nil];
然后复制下面的回调方法
- (void) didRotate:(NSNotification *)notification
{
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
if (orientation == UIDeviceOrientationLandscapeLeft)
{
NSLog(@"Landscape Left!");
self.isLandscapeLeft=1;
}else if(orientation == UIDeviceOrientationLandscapeRight){
NSLog(@"Landscape Right!");
self.isLandscapeLeft=0;
}
}
同样,您可以检查肖像模式的方向,面朝上、面朝下、颠倒以及横向左和横向右方向。:)
关于iphone - 自动旋转的回调方法,iOS和iPad,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10731681/