我想通过按cocos2dx v2 c ++中的按钮将界面方向从landScape更改为肖像
答案 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];
}