views:

1427

answers:

2

Hello! I'm trying to integrate the new object ADBannerView in my Cocos2d game but the banner apears in vertical on the left of the screen when my game is in landscape. This is my code:

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

I'd like the banner to appear on the top of the screen in horizontal (landscape mode).

Thank you for your support!

A: 

You should modify the view frame size & origin in shouldAutorotateToInterfaceOrientation.

Xuki
A: 

You will need to rotate the frame that you made. Try something like this:

// 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 is defined in math.h in the cocos2d library, it's just pi. Once you get it on, just play with the first 2 numbers in the rect to position it where you need it.

Bryan Cimo