Cocos2d-x在iOS上如何使用Admob

3

我想在竖屏界面底部添加Admob的“智能横幅”广告,但代码将广告显示在屏幕顶部。以下是我的代码:

    cocos2d::CCSize size = cocos2d::CCDirector::sharedDirector()->getWinSize();
            CGPoint origin = CGPointMake(size.width,0.0);
    bannerView_ = [[[GADBannerView alloc]
                      initWithAdSize:kGADAdSizeSmartBannerPortrait
                      origin:origin] autorelease];

无论我如何更改原点,广告都显示在屏幕顶部。非常感谢任何帮助。谢谢。
2个回答

2
这是我如何实现在屏幕底部显示广告的方法。
    GADBannerView* bannerView_ = [[GADBannerView alloc] initWithAdSize:kGADAdSizeSmartBannerPortrait];

//For Positioning
    float winHeight = viewController.view.frame.size.height;
    float winWidth = viewController.view.frame.size.width;
    //BannerView y-center is half of it's total height, and co-ordinates have to be calculated with TOP-Left as (0,0). Multiplied by 0.5 for y-center of banner view.
    bannerView_.center=CGPointMake(winWidth/2, winHeight - 0.50 * bannerView_.frame.size.height);

    //bannerView_.autoresizingMask = UIViewAutoresizingFlexibleTopMargin;

    // Let the runtime know which UIViewController to restore after taking
    // the user wherever the ad goes and add it to the view hierarchy.
    bannerView_.rootViewController = viewController;
    [viewController.view addSubview:bannerView_];




GADRequest * request = [GADRequest request];
request.testDevices = [NSArray arrayWithObjects:
                       GAD_SIMULATOR_ID,                               // Simulator
                       nil];
// Initiate a generic request to load it with an ad.
[bannerView_ loadRequest:request];

0
我是这样做的:我创建一个没有起点的横幅。然后当广告加载完成时,触发- (void)adViewDidReceiveAd:(GADBannerView *)bannerView代理方法,在其中将横幅动画从屏幕顶部向下滑动。以下是代码:
- (void)adViewDidReceiveAd:(GADBannerView *)bannerView {

    self.adBannerView = bannerView;

    [UIView animateWithDuration:0.5 delay:0.1 options: UIViewAnimationCurveEaseOut animations:^
         {
             CGSize s = [[CCDirector sharedDirector] winSize];

             CGRect frame = self.adBannerView.frame;

             frame.origin.y = 0;

             self.adBannerView.frame = frame;
         }
                         completion:^(BOOL finished)
         {
         }];
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接