2014-10-05 152 views
2

因此,我最近从客户那里听到关于一个奇怪问题的消息。当他们尝试旋转屏幕时,屏幕会变黑。这似乎只是一个iOS 8的东西,因为我的最新版本只是添加iOS 8的混合。iOS 8自动旋转从屏幕上旋转图像

从我的ViewController:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 

    // 
    // There are 2 ways to support auto-rotation: 
    // - The OpenGL/cocos2d way 
    //  - Faster, but doesn't rotate the UIKit objects 
    // - The ViewController way 
    // - A bit slower, but the UiKit objects are placed in the right place 
    // 

#if GAME_AUTOROTATION==kGameAutorotationNone 
    // 
    // EAGLView won't be autorotated. 
    // Since this method should return YES in at least 1 orientation, 
    // we return YES only in the Portrait orientation 
    // 
    return (interfaceOrientation == UIInterfaceOrientationPortrait); 

#elif GAME_AUTOROTATION==kGameAutorotationCCDirector 
    // 
    // EAGLView will be rotated by cocos2d 
    // 
    // Sample: Autorotate only in landscape mode 
    // 
    if(interfaceOrientation == UIInterfaceOrientationLandscapeLeft) { 
     [[CCDirector sharedDirector] setDeviceOrientation: kCCDeviceOrientationLandscapeRight]; 
    } else if(interfaceOrientation == UIInterfaceOrientationLandscapeRight) { 
     [[CCDirector sharedDirector] setDeviceOrientation: kCCDeviceOrientationLandscapeLeft]; 
    } 

    // Since this method should return YES in at least 1 orientation, 
    // we return YES only in the Portrait orientation 
    return (interfaceOrientation == UIInterfaceOrientationPortrait); 

#elif GAME_AUTOROTATION == kGameAutorotationUIViewController 
    // 
    // EAGLView will be rotated by the UIViewController 
    // 
    // Sample: Autorotate only in landscpe mode 
    // 
    // return YES for the supported orientations 

    return (UIInterfaceOrientationIsLandscape(interfaceOrientation)); 

#else 
#error Unknown value in GAME_AUTOROTATION 

#endif // GAME_AUTOROTATION 


    // Shold not happen 
    return NO; 
} 

-(BOOL)shouldAutorotate 
{ 
    return YES; 
} 


-(NSUInteger)application:(UIApplication*)application supportedInterfaceOrientationsForWindow:(UIWindow *)window 
{ 
    return UIInterfaceOrientationMaskLandscape; 
} 

-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation 
{ 
    return UIInterfaceOrientationLandscapeRight; 
} 

我能够重现我的设备上,以及模拟器....

景观左 Landscape Left 肖像 Portrait 景观右 Landscape Right

从我可以告诉基于这个simi大的iPad测试,是图像实际上在屏幕上自转。即使游戏处于风景中,我目前仍允许所有4个方向,因为我使用的是游戏中心,并且至少一些较老的iOS需要纵向登录。我使用的是cocos2d(v1.1.0-beta2b)的一个相当老的版本,但我以前从未遇到过这样的情况。我可能只需更改支持的方向并关闭自动旋转,但我想修复它。这里发生了什么?

回答

6

我有问题与cocos1.0以及当我编译为ios8。在我的代码中,我发现我有一个用作根视图控制器的UIViewController(它的子节点在Cocos2D使用的EAGLView中)。

我找到的解决方法是从我的UIViewController

-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration 

我已经做了iOS8上和ios7快速测试评论下面的方法,它的作品

+0

工作对我来说也是如此。 – PWiggin 2014-10-15 01:57:03

+0

非常感谢!每次iOS更新都会破坏我的旧cocos2d应用程序,哈哈,我的头撞在墙上。 – Arbel 2015-11-07 06:41:50