如何在Cocos2d中集成AdBannerView

时间:2010-06-10 17:37:03

标签: objective-c cocoa cocos2d-iphone

我正在尝试将新对象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];

我希望横幅以横向(横向模式)显示在屏幕顶部。

感谢您的支持!

2 个答案:

答案 0 :(得分: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。一旦你开启它,只需使用矩形中的前两个数字来定位它所需的位置。

答案 1 :(得分:0)

您应修改视图框尺寸&起源于shouldAutorotateToInterfaceOrientation。