【问题标题】:Cocos2d-x Admob on iOSiOS 上的 Cocos2d-x Admob
【发布时间】:2013-10-13 19:30:52
【问题描述】:

我想在纵向屏幕底部添加 admob“智能横幅”。但是代码在屏幕顶部显示了添加。这是我的代码

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

无论我如何更改广告在屏幕顶部显示的来源。任何帮助都是高度赞赏的。 谢谢

【问题讨论】:

    标签: ios admob cocos2d-x


    【解决方案1】:

    这就是我在屏幕底部显示广告的方式。

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

    【讨论】:

      【解决方案2】:

      我是这样做的:我创建了没有来源的横幅。然后,当广告加载时,- (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)
               {
               }];
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-09-10
        • 1970-01-01
        • 2015-04-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多