我遇到了这里描述的问题: https://devforums.apple.com/thread/165384?tstart=0 我的应用程序崩溃试图加载GameCenter登录屏幕,因为屏幕是纵向的,我的应用程序只支持横向。 我已经尝试了上面的线程中描述的每个解决方案,以及以下线程中的所有解决方案: Crash on presenting UIImagePickerController under iOS 6.0 和这里: http://www.cocos2d-iphone.org/forum/topic/36639
没有一个解决方案有效。崩溃仍然发生,或登录工作正常,然后我的应用程序然后在横向和纵向之间自由旋转,或者它将自身锁定为纵向并拧紧整个UI。
我想要的是让GameCenter登录以纵向方式工作,然后让应用程序中的其他所有内容以横向方式进行。
以下是我的应用中包含的所有轮播方法。这些来自appdelegate.m中的myNavigationController实现:
-(NSUInteger)supportedInterfaceOrientations {
// iPhone only
if( [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone )
return UIInterfaceOrientationMaskLandscape;
// iPad only
return UIInterfaceOrientationMaskLandscape;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// iPhone only
if( [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone )
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
// iPad only
// iPhone only
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
-(BOOL)shouldAutorotate{
return NO;
}
来自appDelegate.m中的AppController实现:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
包含在RootViewController.m中:
-(BOOL)shouldAutorotate{
return NO;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscapeRight|UIInterfaceOrientationMaskLandscapeLeft;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationLandscapeRight;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return NO;
}
#if GAME_AUTOROTATION==kGameAutorotationNone
return ( interfaceOrientation == UIInterfaceOrientationPortrait );
#elif GAME_AUTOROTATION==kGameAutorotationCCDirector
if( interfaceOrientation == UIInterfaceOrientationLandscapeLeft ) {
[[CCDirector sharedDirector] setDeviceOrientation: kCCDeviceOrientationLandscapeRight];
} else if( interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
[[CCDirector sharedDirector] setDeviceOrientation: kCCDeviceOrientationLandscapeLeft];
}
#elif GAME_AUTOROTATION == kGameAutorotationUIViewController
#else
#error Unknown value in GAME_AUTOROTATION
#endif // GAME_AUTOROTATION
// Shold not happen
return NO;
}
kGameAutorotationUIViewController
#if GAME_AUTOROTATION == kGameAutorotationUIViewController
-(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];
UIView *glView = [[CCDirector sharedDirector] view];;
float contentScaleFactor = [director contentScaleFactor];
if( contentScaleFactor != 1 ) {
rect.size.width *= contentScaleFactor;
rect.size.height *= contentScaleFactor;
}
glView.frame = rect;
}
#endif // GAME_AUTOROTATION == kGameAutorotationUIViewController
答案 0 :(得分:2)
几天前刚刚在这里回答了这个问题: Cocos 2d 2.0 shouldAutorotate not working?
有关于您需要做什么才能使其在该答案中起作用的说明。希望这有帮助!