如何在一个视图中使用多个 iAd 横幅 (iPhone/iPad)

发布于 2024-12-11 07:48:25 字数 2121 浏览 0 评论 0原文

我正在尝试设置多个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不爱素颜 2024-12-18 07:48:25

在委托方法中,您可以通过简单的比较来检查它是关于哪个横幅:

- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
    if (banner == adView) {
        // do something with banner 1
    }
    else if (banner == adViewTwo) {
        // do something with banner 2
    }
}

In delegate methods you can check which banner it is about by a simple comparation:

- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
    if (banner == adView) {
        // do something with banner 1
    }
    else if (banner == adViewTwo) {
        // do something with banner 2
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文