【问题标题】:How to integrate AdBannerView in Cocos2d如何在 Cocos2d 中集成 AdBannerView
【发布时间】:2010-06-10 17:37:03
【问题描述】:

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

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

感谢您的支持!

【问题讨论】:

    标签: objective-c cocoa cocos2d-iphone


    【解决方案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。安装后,只需使用矩形中的前 2 个数字即可将其放置在您需要的位置。

    【讨论】:

      【解决方案2】:

      您应该在 shouldAutorotateToInterfaceOrientation 中修改视图框架大小和原点。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多