Reputation: 11
i'm using Cocos2d-iphone v3.0 combined with sprite-builder to build my app.I just recently got iAd working following the answer seen here: How to add iAd in Cocos-SpriteBuilder
So i wont repeat any of the code, the only thing I changed from the posted answer was _adView to _bannerView in init statement. Now I have adds showing where I want but I dont know how to hide them. I would like to have the adds only visible in the game scene after you loose. When you loose I run a gameover event that displays your highscore and a restart button amongst other things so setting a variable like canShowAds to true there and false when the scene starts seems like what I would have to do but I don't know how to only run the ads when its equal to true. Also I plan on having a remove ads button so I would need to check if that has been purchased. If you need anymore code posted I will gladly post it. :)
Upvotes: 1
Views: 1025
Reputation: 22042
Try this:
-(void)hideBannerView
{
if (!_adBannerViewIsVisible)
{
return;
}
if (_adBannerView)
{
_adBannerViewIsVisible = false;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
CGSize s = [[CCDirector sharedDirector] viewSize];
CGRect frame = _adBannerView.frame;
if(isBannerOnTop) //use any one..
{
frame.origin.x = 0.0f;
frame.origin.y = -_adBannerView.frame.size.height ;
}
else
{
frame.origin.x = 0.0f;
frame.origin.y = s.height ;
}
_adBannerView.frame = frame;
[UIView commitAnimations];
}
}
Upvotes: 3