I am trying to set up multiple iAd banners to be shown in a single view (one at the top of the screen just below the nav bar, the other at the very bottom of the screen). However I’m having an issue moving them on and off the screen.
I believe it is due to the delegate method not knowing which banner to move however I’m not sure how to fix the issue. Here is the code I am using at present:
- (void)createIAdBanner
{
adView = [[ADBannerView alloc] initWithFrame:CGRectZero];
adView.frame = CGRectOffset(adView.frame, 0, -50);
adView.requiredContentSizeIdentifiers = [NSSet setWithObject:ADBannerContentSizeIdentifierPortrait];
adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
adViewTwo = [[ADBannerView alloc] initWithFrame:CGRectZero];
adViewTwo.frame = CGRectOffset(adView.frame, 0, 530);
adViewTwo.requiredContentSizeIdentifiers = [NSSet setWithObject:ADBannerContentSizeIdentifierPortrait];
adViewTwo.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
[self.view addSubview:adView];
[self.view addSubview:adViewTwo];
adView.delegate=self;
adViewTwo.delegate=self;
self.bannerIsVisible=NO;
self.bannerTwoIsVisible=NO;
}
- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
if (!self.bannerIsVisible)
{
[UIView beginAnimations:@"animateAdBannerOn" context:NULL];
banner.frame = CGRectOffset(banner.frame, 0, 94);
[UIView commitAnimations];
self.bannerIsVisible = YES;
}
if (!self.bannerTwoIsVisible)
{
[UIView beginAnimations:@"animateAdBannerOn" context:NULL];
banner.frame = CGRectOffset(banner.frame, 0, 430);
[UIView commitAnimations];
self.bannerTwoIsVisible = YES;
}
}
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
if (self.bannerIsVisible)
{
[UIView beginAnimations:@"animateAdBannerOff" context:NULL];
banner.frame = CGRectOffset(banner.frame, 0, -50);
[UIView commitAnimations];
self.bannerIsVisible = NO;
}
if (self.bannerTwoIsVisible)
{
[UIView beginAnimations:@"animateAdBannerOff" context:NULL];
banner.frame = CGRectOffset(banner.frame, 0, 530);
[UIView commitAnimations];
self.bannerIsVisible = NO;
}
}
In delegate methods you can check which banner it is about by a simple comparation: