2011-05-15 28 views
0

我用茯苓通過AdMob合併,nomarl我的應用程序的工作不錯,但回來後打了廣告,並返回遊戲,它錯佈局自動旋轉屏幕錯誤來自網頁流量

後,這是我的輪換代碼

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

-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration 
{ 
    CGRect screenRect = [[UIScreen mainScreen] bounds]; 
    CGRect rect; 

    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; 
} 

感謝您的幫助!

回答

1

我之前有過類似的問題,而且我做的不正確的是我創建了一個新的UIViewController,並將其設置爲rootViewController以用於AdMob視圖。我現在正在做我的應用程序是這樣的:

adMobView.rootViewController = [RootViewController sharedInstance]; 
[[[CCDirector sharedDirector] openGLView] addSubview:adMobView]; 

其中[RootViewController sharedInstance]是一個類方法,它返回RootViewController的唯一實例的應用程序。請參閱https://stackoverflow.com/a/10222956/1241690

(有關的cocos2d 2.x的,第二行應該是:

[[[CCDirector sharedDirector] view] addSubview:adMobView];