通过按下按钮将界面方向从landScape更改为纵向

时间:2014-06-25 06:44:21

标签: cocos2d-x

我想通过按cocos2dx v2 c ++中的按钮将界面方向从landScape更改为肖像

1 个答案:

答案 0 :(得分:1)

添加一个类变量

Bool isInLandsCapeOrientation;
viewDidLoad

中的

将此标志设置为

isInLandsCapeOrientation = false;

添加以下功能

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

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

要将方向从纵向更改为横向,请在按钮操作

上进行
- (IBAction)changeOrientationButtonPressed:(UIButton *)sender
{
isInLandsCapeOrientation = true;
UIViewController *viewController = [[UIViewController alloc] init];
[self presentModalViewController:viewController animated:NO];
[self dismissModalViewControllerAnimated:NO];
}