iOS 8自动旋转将图像从屏幕上旋转出来

时间:2014-10-05 16:54:58

标签: cocos2d-iphone ios8

所以我最近听到了客户关于一个奇怪问题的消息。当他们试图旋转屏幕时,屏幕会变黑。这似乎是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

据我所知,基于此类似的iPad测试,图像实际上是在屏幕上自动旋转。我目前允许所有4个方向,即使游戏是在风景中,因为我正在使用游戏中心,并且至少一些较旧的iOS需要纵向登录。我正在使用相当旧版本的cocos2d(v1.1.0-beta2b),但我以前从未经历过这样的事情。我可以只改变支持的方向并关闭自动旋转,但我想修复它。这是怎么回事?

1 个答案:

答案 0 :(得分:6)

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

我找到的修复是从我的UIViewController

注释以下方法
-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration

我已经对ios8和ios7进行了快速测试,并且可以正常运行