Cocos 2d 2.0 shouldAutorotate not working?

帅比萌擦擦* 提交于 2019-12-13 02:25:12

问题


I'm having some issues. I have a cocos2d game I'm just about done developing. However I've run into a problem where I need to enable portrait orientation in my apps plist for game center sign in to work without throwing a SIGABRT error. So once I enable that from my app's build summary page (Or add it to the info.plist file as a supported orientation) it works fine. But then anytime in my game if you turn the iPhone it will flip to portrait mode if it senses you turned it that way. I've tried messing with the shouldAutorotateToInterfaceOrientation method from my AppDelegate.m and it's not getting called AT ALL, not at any time is it being called. I threw an NSLog statement in the method to be sure if it's being called, and it's not.

So, basically my real issue is. I need my game to STAY in landscape mode BESIDES when the Game Center login screen pops up. How do I do this in a Cocos2d 2.0 game?

I'm am using iOS6


回答1:


First, make sure that the app supports portrait and landscape orientations in the target summary.

Then you'll need to make a new root view controller that forces you into landscape mode so that your game doesn't start rotating strangely:

@implementation CUSTOM_RootViewController
-(NSUInteger)supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskLandscape;
}

- (BOOL)shouldAutorotate {
    return YES;
}

@end

Finally, in the AppDelegate.m file, replace the original navigation controller with your new one:

// Create a Navigation Controller with the Director
//navController_ = [[UINavigationController alloc] initWithRootViewController:director_];
navController_ = [[SMD_RootViewController alloc] initWithRootViewController:director_];
navController_.navigationBarHidden = YES;

Now you should be able to overlay a portrait view on top.

Hope this helps!




回答2:


Use this code in AppDelegate.mm

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_6_0

-(NSUInteger)supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskLandscape;
}

- (NSUInteger)application:(UIApplication*)application supportedInterfaceOrientationsForWindow:(UIWindow*)window
{
    return UIInterfaceOrientationMaskLandscape;
}
#else
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
#endif



回答3:


In IOs6 shouldAutorotateToInterfaceOrientation method not worked, so u change in appDelegate .m file [window addSubview:viewcontroller] to [window setRootviewcontroller:viewcontroller] after its works fine.



来源:https://stackoverflow.com/questions/13718761/cocos-2d-2-0-shouldautorotate-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!