2013-02-15 257 views
1

我有一個ioc橫幅廣告在Cocos2d應用程序中工作。如果橫幅廣告移動,iAd橫幅不可點擊

下面是我用來展示廣告的CCLayer子類的代碼。在DidLoad上,添加變得可見並且底部菜單向上滑動以補償。

-(id) init 
{ 
    if((self=[super init])) { 
     CGSize size = [[CCDirector sharedDirector] winSize]; 

     UIViewController *controller = [[UIViewController alloc] init]; 
     controller.view.frame = CGRectMake(0, size.height -32, 320, 32); 

     ADBannerView *adView = [[ADBannerView alloc] initWithFrame:CGRectZero]; 

     adView.requiredContentSizeIdentifiers = [NSSet setWithObject:ADBannerContentSizeIdentifierLandscape]; 

     adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierLandscape; 
     [controller.view addSubview:adView]; 
     adView.delegate = self; 

     [[[CCDirector sharedDirector] view] addSubview:controller.view]; 
     [[[CCDirector sharedDirector] view] setNeedsLayout]; // I was told this would fix it, but it fails to. 
    } 

    return self; 
} 


- (void)bannerViewDidLoadAd:(ADBannerView *)banner 
{ 
    if (!bannerIsVisible) 
    { 
     NSLog(@"bannerViewDidLoadAd"); 
     [UIView beginAnimations:@"animateAdBannerOn" context:NULL]; 
     banner.frame = CGRectOffset(banner.frame, 0, -32); //the offending line 

     self.position = ccpAdd(ccp(0, 32), self.position); 

     [UIView commitAnimations]; 
     bannerIsVisible = YES; 


    } 
} 
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error 
{ 
    if (bannerIsVisible) 
    { 
     NSLog(@"bannerView:didFailToReceiveAdWithError:"); 
     [UIView beginAnimations:@"animateAdBannerOff" context:NULL]; 
     banner.frame = CGRectOffset(banner.frame, 0, 32); //the other offending line 
     self.position = ccpAdd(ccp(0, -32), self.position); 

     [UIView commitAnimations]; 
     bannerIsVisible = NO; 
    } 

} 

當這些行被禁用時,橫幅是可點擊的,但醜陋的白色橫幅是可見的。這是怎麼回事?我如何修復或解決它?

回答

3

Cocos2d_2.0_iAd_Sample

Cocos2d_3.0_iAd_Sample

在場景中做到這一點。

-(void)onEnter 
{ 
    [super onEnter]; 
        
     mIAd = [[MyiAd alloc] init]; 
  
} 
      
-(void)play 
{ 
    [self hideAdsBanner]; 
} 

-­(void)hideAdsBanner 
{ 
    if(mIAd) 
    [mIAd RemoveiAd ]; 
  
} 
  
­-(void)onExit 
{ 
    if(mIAd) 
    { 
        [mIAd release]; 
        mIAd = nil; 
    } 
    [super onExit]; 
  
}