当我从Landscapeleft旋转到LandscapeRight和LandscapeRight到LandscapeLeft时,我的应用程序显示黑屏

时间:2016-04-26 09:56:48

标签: ios iphone cocos2d-iphone cocos2d-x uiinterfaceorientation

您好我是iOS开发人员的新手。

当我将LandscapeLeft旋转到LandscapeRight时,我的应用有问题,我的应用显示屏显示黑屏。

我正在使用此方法进行旋转。

 -(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];
    EAGLView *glView = [director openGLView];
    float contentScaleFactor = [director contentScaleFactor];

    if( contentScaleFactor != 1 ) {
        rect.size.width *= contentScaleFactor;
        rect.size.height *= contentScaleFactor;
    }
    glView.frame = rect;
}

0 个答案:

没有答案