2013-10-13 67 views
3

我想在肖像畫面的底部添加admob「智能橫幅」。但代碼顯示屏幕頂部的增加。這裏是我的代碼iOS上的Cocos2d-x Admob

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

無論我如何更改廣告顯示在屏幕頂部的原點。任何幫助高度appriciated。 謝謝

回答

0

我這樣做了:我創建了沒有起源的橫幅。然後,當廣告加載時,委託方法被激發,並且在其中爲橫幅設置動畫,使其從屏幕頂部向下滑動。這裏是代碼:

- (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) 
     { 
     }]; 
} 
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];