滚动视图中的iAd [英] iAds in a Scrolling View

查看:125
本文介绍了滚动视图中的iAd的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我想在表视图控制器中显示iAd,它同时包含导航栏和Tab栏。我能够在我的应用程序中显示iAd,但是当我尝试滚动时,这个iAd会出现问题,问题是iAd也在滚动单元格,因为我无法在底部查看单元格。我正在使用下面的代码创建iAd。可以帮助我解决以下问题。

In my application I want to show iAd in table view controller which have both navigation bar and Tab bar. I am able to show iAd in my application but this iAd is give trouble when I try to scroll, the problem is that iAd is also scrolling with the cells due to which I am not able to view the cell in bottom. I am creating the iAd using below code. can some one help me out in resolving following issue.

#pragma mark -
#pragma mark === Banner View Methods ===
#pragma mark -

- (void)createBannerView {

    Class cls = NSClassFromString(@"ADBannerView");
    if (cls) {
        ADBannerView *adView = [[cls alloc] initWithFrame:CGRectZero];
        adView.requiredContentSizeIdentifiers = [NSSet setWithObjects:ADBannerContentSizeIdentifierPortrait,
                                                 ADBannerContentSizeIdentifierLandscape, nil];

        // Set the current size based on device orientation
        adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
        adView.delegate = self;

        adView.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleRightMargin;

        // Set intital frame to be offscreen
        CGRect bannerFrame =adView.frame;
        bannerFrame.origin.y = self.view.frame.size.height;
        adView.frame = bannerFrame;

        self.bannerView = adView;

        [self.view addSubview:adView];
        [adView release];
    }
}

- (void)showBanner {

    CGFloat fullViewHeight = self.view.frame.size.height;
    CGRect tableFrame = self.tv.frame;
    CGRect bannerFrame = self.bannerView.frame;

    // Shrink the tableview to create space for banner
    tableFrame.size.height = fullViewHeight - bannerFrame.size.height;

    // Move banner onscreen
    bannerFrame.origin.y = fullViewHeight - bannerFrame.size.height; 

    [UIView beginAnimations:@"showBanner" context:NULL];
    self.tv.frame = tableFrame;
    self.bannerView.frame = bannerFrame;
    [UIView commitAnimations];
}

- (void)hideBanner {

    // Grow the tableview to occupy space left by banner
    CGFloat fullViewHeight = self.view.frame.size.height;
    CGRect tableFrame = self.tv.frame;
    tableFrame.size.height = fullViewHeight;

    // Move the banner view offscreen
    CGRect bannerFrame = self.bannerView.frame;
    bannerFrame.origin.y = fullViewHeight;

    self.tv.frame = tableFrame;
    self.bannerView.frame = bannerFrame;
}

- (void)releaseBanner {

    if (self.bannerView) {
        bannerView.delegate = nil;
        self.bannerView = nil;
    }
}

- (void)changeBannerOrientation:(UIInterfaceOrientation)toOrientation {

    if (UIInterfaceOrientationIsLandscape(toOrientation)) {
        self.bannerView.currentContentSizeIdentifier = 
        ADBannerContentSizeIdentifierLandscape;
    }
    else {
        self.bannerView.currentContentSizeIdentifier = 
        ADBannerContentSizeIdentifierPortrait;
    }
}

#pragma mark -
#pragma mark === ADBannerViewDelegate Methods ===
#pragma mark -

- (void)bannerViewDidLoadAd:(ADBannerView *)banner {

    [self showBanner];
}

- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error {

    [self hideBanner];
}


推荐答案

yes i got it you use addSubView which i think is wrong Add this Banner in last cell of a tableview or in a fotter of a table view if you are not use load more functionalty in you app
– tableView:viewForFooterInSection:
use that delegate method of table view UItableViewDelegate i think it helps you
– tableView:heightForFooterInSection:
add that method too to specify the height of footer of your table
add the calculate banner size code in
– tableView:heightForFooterInSection:
and add banner in – tableView:heightForFooterInSection:

这篇关于滚动视图中的iAd的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆