gpt4 book ai didi

objective-c - Cocos2d中如何集成AdBannerView

转载 作者:搜寻专家 更新时间:2023-10-30 20:27:29 25 4
gpt4 key购买 nike

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

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

感谢您的支持!

最佳答案

您需要旋转您制作的框架。尝试这样的事情:

// 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。打开后,只需使用矩形中的前 2 个数字将其放置在您需要的位置。

关于objective-c - Cocos2d中如何集成AdBannerView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3016936/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com