我在使用Cocos2d 2.0时遇到了同样的问题。
我的问题是,这个项目已经发展了几年,并携带了一些现在已经过时的文件,如RootViewController、UIViewController和MyRootViewController等。它们当时可以工作,但显然引起了今天审查委员会的注意,因为我收到了“所有iPhone应用程序必须在iPad上运行”的拒绝通知。在大声喊叫并最终接受失败后,我认为这个政策使得制作一个仅限于iPhone的应用程序变得非常困难。如果我对此有误,请告诉我。
尽管我当时(现在仍然)感到不安,但我想也许现在我至少可以用更优雅的解决方案来清理项目,处理基本问题:设备旋转+内容旋转。最终,我使用了从一个更近期的项目中借鉴的东西,它看起来更加优雅,而且实际上也起作用:只需将MyNavigationController添加到我的AppDelegate的顶部即可。
我已经添加了下面的代码。我相信它可以改进。如果您能增强它,请评论。
因此,我能够删除旧的RootViewController和MyRootViewController文件,现在更容易维护。我从来没有真正理解它们的目的。好了,终于摆脱了!
这是我显示和匹配设备方向+内容方向的解决方案:
在AppDelegate.h中,我必须声明我正在做什么:
//文件顶部
@interface MyNavigationController : UINavigationController
@end
//在AppDelegate.h接口内部
MyNavigationController *navController_;
//在@end之前的文件底部
@property (readonly) MyNavigationController *navController;
这是在我的AppDelegate.m顶部工作的代码:
@implementation MyNavigationController
-(NSUInteger)supportedInterfaceOrientations {
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
if (orientation == UIDeviceOrientationPortrait) {
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
} else {
[[CCDirectorIOS sharedDirector] pushScene:[VerticalDisplayLayer scene]];
return UIInterfaceOrientationMaskPortrait;
}
} else if (orientation == UIDeviceOrientationLandscapeLeft) {
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
} else {
[[CCDirectorIOS sharedDirector] pushScene:[MainMenuScene scene]];
}
} else if (orientation == UIDeviceOrientationLandscapeRight) {
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
} else {
[[CCDirectorIOS sharedDirector] pushScene:[MainMenuScene scene]];
}
} else if (orientation == UIDeviceOrientationPortraitUpsideDown) {
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
} else {
[[CCDirectorIOS sharedDirector] pushScene:[VerticalDisplayLayer scene]];
return UIInterfaceOrientationMaskPortraitUpsideDown;
}
} else {
}
return UIInterfaceOrientationMaskLandscape;
}
- (BOOL)shouldAutorotate {
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
if( [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone ) {
if (orientation == UIDeviceOrientationPortrait) {
[[CCDirectorIOS sharedDirector] pushScene:[VerticalDisplayLayer scene]];
return UIInterfaceOrientationMaskPortrait;
}
if (orientation == UIDeviceOrientationPortraitUpsideDown) {
[[CCDirectorIOS sharedDirector] pushScene:[VerticalDisplayLayer scene]];
return UIInterfaceOrientationMaskPortraitUpsideDown;
}
if (orientation == UIDeviceOrientationLandscapeLeft) {
return UIInterfaceOrientationMaskLandscape;
}
if (orientation == UIDeviceOrientationLandscapeRight) {
return UIInterfaceOrientationMaskLandscape;
}
return TRUE;
}
if( [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad ) {
return TRUE;
}
return TRUE;
}
- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation
{
if( [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone )
return TRUE;
if( [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad )
return TRUE;
return TRUE;
}
-(void) directorDidReshapeProjection:(CCDirector*)director
{
if(director.runningScene == nil) {
[director runWithScene: [MainMenuScene scene]];
}
}
-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGRect rect = CGRectZero;
if(toInterfaceOrientation == UIInterfaceOrientationPortrait || toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
rect = screenRect;
} else if(toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) {
rect.size = CGSizeMake( screenRect.size.height, screenRect.size.width );
}
CCDirector *director = [CCDirector sharedDirector];
CCGLView *glView = (CCGLView *)[director view];
glView.frame = rect;
}
@end
以下是我必须解决这个问题的原因:
- 我需要横向和纵向模式来显示不同的场景。
以下是一些截图,描述了这种情况。