iAds in a Scrolling View

杀马特。学长 韩版系。学妹 提交于 2019-12-11 14:04:19

问题


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];
}

回答1:


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:


来源:https://stackoverflow.com/questions/5442089/iads-in-a-scrolling-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!