2014-10-05 151 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