2010-06-10 41 views
3

我正在嘗試將新對象ADBannerView集成到我的Cocos2d遊戲中,但當遊戲處於橫向模式時,屏幕左側的垂直橫幅將顯示在屏幕上。這是我的代碼:如何將AdBannerView集成到Cocos2d中

UIViewController *controller = [[UIViewController alloc] init]; 
controller.view.frame = CGRectMake(0,0,480,32); 

//From the official iAd programming guide 
ADBannerView *adView = [[ADBannerView alloc] initWithFrame:CGRectZero]; 

adView.requiredContentSizeIdentifiers = [NSSet setWithObject:ADBannerContentSizeIdentifier480x32]; 

adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifier480x32; 

[controller.view addSubview:adView]; 

//Then I add the adView to the openglview of cocos2d 
[[Director sharedDirector] openGLView] addSubview:controller.view]; 

我想橫幅出現在屏幕的頂部水平(橫向模式)。

感謝您的支持!

回答

1

您需要旋轉所製作的框架。試試這樣:

// lower right:-136, 295, 320, 32 lower left:-136, 135, 320, 32 upper right:136, 295, 320, 32 
UIViewController *controller = [[UIViewController alloc] init]; 
controller.view.frame = CGRectMake(136, 135, 320, 32); 
controller.view.transform = CGAffineTransformMakeRotation(M_PI/2.0); // turn 180 degrees 

//From the official iAd programming guide 
ADBannerView *adView = [[ADBannerView alloc] initWithFrame:CGRectZero]; 

adView.requiredContentSizeIdentifiers = [NSSet setWithObject:ADBannerContentSizeIdentifier480x32]; 

adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifier480x32; 

[controller.view addSubview:adView]; 

//Then I add the adView to the openglview of cocos2d 
[[Director sharedDirector] openGLView] addSubview:controller.view]; 

M_PI在cocos2d庫的math.h中定義,它只是pi。一旦你開始使用它,只需要玩弄前兩個數字就可以將它放在你需要的地方。

0

您應該在shouldAutorotateToInterfaceOrientation中修改視圖框架大小&的來源。