0

I want to change Interface Orientation from landScape to portrait by pressing a button in cocos2dx v2 c++

GameDeveloper
  • 1,029
  • 1
  • 7
  • 12

1 Answers1

1

Add a class variable

Bool isInLandsCapeOrientation;

in viewDidLoad

set this flag to

isInLandsCapeOrientation = false;

Add the following function

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
 if (!isInLandsCapeOrientation) {
     return (UIInterfaceOrientationIsPortrait(interfaceOrientation));

 }else {
     return  (UIInterfaceOrientationIsLandscape(interfaceOrientation));
 }
}

To changing orientation from portrait to landscape, let it happens on a button action

- (IBAction)changeOrientationButtonPressed:(UIButton *)sender
{
isInLandsCapeOrientation = true;
UIViewController *viewController = [[UIViewController alloc] init];
[self presentModalViewController:viewController animated:NO];
[self dismissModalViewControllerAnimated:NO];
}
pankaj asudani
  • 862
  • 6
  • 18