如何在一个视图中使用多个 iAd 横幅 (iPhone/iPad)
我正在尝试设置多个 iAd 横幅在单个视图中显示(一个位于屏幕顶部导航栏下方,另一个位于屏幕最底部)。但是,我在将它们移入和移出屏幕时遇到问题。
我相信这是由于委托方法不知道要移动哪个横幅,但我不确定如何解决该问题。这是我目前使用的代码:
- (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;
}
}
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;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在委托方法中,您可以通过简单的比较来检查它是关于哪个横幅:
In delegate methods you can check which banner it is about by a simple comparation: