Search code examples
iosiphoneobjective-ccocos2d-x

ios set specific orientation for specific views


I am making game which supports only landscape orientation but I am also using a library to share my game video but that share screen require portrait orientation , If I don't enable portrait orientation my game got crash but If I enable portrait orientation to avoid this crash then my whole game become useless by becoming portrait as it is only for landscape.

This is my game Landscape View as shown by figures below,

This is my game LandScape View

This is the Library Portrait View to Share video

This is the Library Portrait View to Share video

My Game View after sharing video from library My Game View after video share

Please help me How can I enable portrait orientation for this library to avoid crash and my rest of the app always remain in landscape and it never goes to portrait orientation. Thanks


Solution

  • Add the following method to your application's AppDelegate.m file:

    // IOS 6
    
    -(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
      return UIInterfaceOrientationMaskAll;
    }
    

    In both cases you must also make sure that you have added the landscape only orientation handling code to your game's main UIViewController.

    // IOS 5
    
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
      return UIInterfaceOrientationIsLandscape(toInterfaceOrientation);
    }
    
    // IOS 6
    
    - (BOOL)shouldAutorotate {
       return YES;
    }
    
    - (NSUInteger)supportedInterfaceOrientations {
      return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
    }