1

我有这个webViewDidFinishLoad

- (void)setupAdBanner {
    adView = [[ADBannerView alloc] initWithFrame:CGRectZero];
    CGRect adFrame = adView.frame;
    if([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortrait
       || [UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortraitUpsideDown) {
        adView.currentContentSizeIdentifier =
        ADBannerContentSizeIdentifierPortrait;
        adFrame.origin.y = self.view.frame.size.height-adView.frame.size.height;
    } else {
        adView.currentContentSizeIdentifier =
        ADBannerContentSizeIdentifierLandscape;
        adFrame.size.width = adView.frame.size.width;
        adFrame.origin.y = self.view.frame.size.height-adView.frame.size.height;
    }
    adView.frame = adFrame;

    [self.view addSubview:adView];
}

这与我的 phonegap 应用程序中的 HTML 内容重叠。如何调整我的 webview 框架大小以适应广告横幅?

4

1 回答 1

1

我有这个确切的问题。我在这里写了关于我的解决方案的博客http://hawkinbj.wordpress.com/2013/04/16/implement-iad-banner-ads-without-covering-uiwebview-in-phonegap/

您需要实现 ADBannerViewDelegateProtocolReference。在 MainViewController.h 中:

@interface MainViewController : CDVViewController <ADBannerViewDelegate> 
{
    ADBannerView *adView;
}
@end

其余步骤在 MainViewController.m 中。

在 webViewDidFinishLoad 中:

adView.delegate = self;

添加这两个方法:

- (void)bannerViewDidLoadAd:(ADBannerView *)banner 
{
    CGRect resizedWebView = [super webView].frame;
    resizedWebView.size.height = adView.frame.origin.y;
    [super webView].frame = resizedWebView;
    [self.view bringSubviewToFront:adView];
    adView.hidden = NO;
} 

- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
    CGRect resizedWebView = [super webView].frame;
    resizedWebView.size.height = self.view.frame.size.height;
    [super webView].frame = resizedWebView;
    adView.hidden = YES;
}

神奇的是 [self.view bringSubviewToFront:adView];

于 2013-04-17T12:13:57.333 回答