2011-12-30 73 views
1

當您查看下面的內容時,在橫向模式下可以自動旋轉。如何在cocos2d中以縱向模式設置自動旋轉?

那麼如何自動旋轉肖像模式?

如何設置?

- (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; 
} 

回答

1

如果更改shouldAutorotateToInterfaceOrientation只:

return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown) 

它將爲除肖像所有方向顛倒旋轉。

相關問題