cocos2d v3 re-orient screen during App use

删除回忆录丶 提交于 2019-12-20 06:37:24

问题


So in cocos2d (I believe I was on v2.1) I did this to lock and set the orientations:

        AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];

    const UIInterfaceOrientation ORIENTATION = delegate.navController.interfaceOrientation;
    delegate.navController.
    delegate.navController.screenOrientation = ORIENTATION == UIInterfaceOrientationMaskPortrait;
    UIViewController *mVC = [[UIViewController alloc] init];
    [delegate.navController presentModalViewController:mVC animated:NO];
    [delegate.navController dismissModalViewControllerAnimated:NO];

With some functions added to the AppDelegate. I cannot seem to get the same results in iOS7 and cocos2d v3.

I have dug through a bit and the proper functions seem to be in place but cannot seem to set up a global variable to set the orientation and return only the one I want at the certain time. Can someone point me down the proper path. I think I'm missing something really small cause the proper code seems to be there already.

Here's the code for my AppDelegate

@implementation AppDelegate

-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [self setupCocos2dWithOptions:@{
        CCSetupShowDebugStats: @(NO),
    }];

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];

return YES;

}

-(CCScene *)startScene
{
    return [HomeScreen scene];
}

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscape;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}

My code never hits the interfaceOrientation functions.

Thoughts??!?


回答1:


After a couple days fooling around I figured out a solution:

in AppDelegate I needed this function:

-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
    if (!self.lockedToOrientation) {
        if( [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone ){
            return UIInterfaceOrientationMaskPortrait;
        }

        return UIInterfaceOrientationMaskPortrait;
    }
    else {
        return self.lockedToOrientation;
    }
}

Where

@property UIInterfaceOrientationMask lockedToOrientation;

Hope this helps someone!

Cheers.



来源:https://stackoverflow.com/questions/22353111/cocos2d-v3-re-orient-screen-during-app-use

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