Device Orientation in Cocos2d-iOS

Xcode: 7.1, works on: iPhone 6s Plus

My AppDelegate.mm has the following code:

- (void) applicationDidFinishLaunching:(UIApplication*)application
---------some code
#if GAME_AUTOROTATION == kGameAutorotationUIViewController
     NSLog(@"if");
    [director setDeviceOrientation:kCCDeviceOrientationLandscapeLeft];
#else
          NSLog(@"else");
    [director setDeviceOrientation:kCCDeviceOrientationPortrait];
#endif
---------somecode

My GameConfig.h has:

#define GAME_AUTOROTATION kGameAutorotationUIViewController

My RootViewController.m has:

if GAME_AUTOROTATION == kGameAutorotationUIViewController
    return ( UIInterfaceOrientationIsLandscape( interfaceOrientation ) );

My Xcode Settings: enter image description here

Although the orientation of the device goes to landscape, the game appears in portrait orientation. Game screenshot: enter image description here

+4
source share
1 answer

Add SupportInterfaceOrientations function to RootViewController.m

-(NSUInteger)supportedInterfaceOrientations {

    // iPhone only
    if( [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone )
        return UIInterfaceOrientationMaskLandscape;

    // iPad only
    return UIInterfaceOrientationMaskLandscape;
}
+1
source

Source: https://habr.com/ru/post/1617495/


All Articles