1

我在我的游戏中使用 Facebook SDK 以便在 Facebook 上发布一些分数。我的代码使用的是 Cocos2D 框架,所以我不得不添加一些代码来启用 UIView。一切正常,除了视图以纵向显示,尽管我的笔尖属性指示横向,ShouldautoRotate 方法返回横向,并且应用程序方向也是横向。这是设置视图的代码:

// share to facebook methods
-(void)shareFacebookSelected
{
[[SimpleAudioEngine sharedEngine]stopBackgroundMusic];
[[CCDirector sharedDirector] pause];

 if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
    myViewController1 = [[HFViewController alloc] initWithNibName:@"HFViewController_iPhone" bundle:nil];

 } else {
     myViewController1 = [[HFViewController alloc] initWithNibName:@"HFViewController_iPad" bundle:nil];
 }


UIWindow* window = [[[UIApplication sharedApplication] windows] objectAtIndex:0];

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.75];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:window cache:YES];


[[[CCDirector sharedDirector]view] removeFromSuperview];

myViewController1.view.hidden = false;

[window addSubview:myViewController1.view];


[UIView commitAnimations];

}

我还启用了一个按钮以返回到正常的 cocos 游戏并删除 UIView,但在返回时,即使我的主要游戏方向已更改为纵向。

有任何想法吗???

4

1 回答 1

0

以下几行解决了我的问题:

#define DegreesToRadians(x) ((x) * M_PI / 180.0)
CGRect screenRect = [[UIScreen mainScreen]bounds];
 myViewController1.view.transform = CGAffineTransformMakeRotation(DegreesToRadians(90));
myViewController1.view.hidden = false;
myViewController1.view.frame = screenRect;

我基本上将视图旋转了 90 度,这不是最优雅的解决方案,只是蛮力但它有效。我仍然想了解它为什么呈现它的方式,哦,好吧

于 2013-11-03T12:55:03.700 回答