2010-06-10 36 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中修改视图框架大小&的来源。