在 iPad 中隐藏 Admob 广告视图
Hide Admob ads view in iPad
我使用以下代码在屏幕底部中央放置了一个 Admob 横幅:
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
CGPoint origin = CGPointMake(0.0,
self.view.frame.size.height -
CGSizeFromGADAdSize(kGADAdSizeBanner).height);
bannerView_ = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner
origin:origin];
bannerView_.center = CGPointMake(self.view.center.x, self.view.frame.size.height-CGSizeFromGADAdSize(kGADAdSizeBanner).height/2);
bannerView_.adUnitID = @"myid";
bannerView_.rootViewController = self;
[self.view addSubview:bannerView_];
[bannerView_ loadRequest:[GADRequest request]];
}
但是,在iPad,我打算在另一个位置投放不同的广告。因此,我需要在 iPad 中隐藏此广告。我可以这样做吗?
试试这个
bannerView_.hidden=true;
您不需要创建多个横幅视图。更简单的解决方案是使用相同的横幅视图,但在定位视图之前检查当前设备习惯用法。例如,这里是您提供的修改后的代码,用于检查用户使用的是哪个设备:
- (void) webViewDidFinishLoad: (UIWebView*) webView
{
CGPoint origin = CGPointMake(0.0,
self.view.frame.size.height -
CGSizeFromGADAdSize(kGADAdSizeBanner).height);
bannerView_ = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner
origin:origin];
bannerView_.center = CGPointMake(self.view.center.x, self.view.frame.size.height-CGSizeFromGADAdSize(kGADAdSizeBanner).height/2);
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
// Change the banner's center/origin here for the iPad.
}
bannerView_.adUnitID = @"myid";
bannerView_.rootViewController = self;
[self.view addSubview:bannerView_];
[bannerView_ loadRequest:[GADRequest request]];
}
我使用以下代码在屏幕底部中央放置了一个 Admob 横幅:
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
CGPoint origin = CGPointMake(0.0,
self.view.frame.size.height -
CGSizeFromGADAdSize(kGADAdSizeBanner).height);
bannerView_ = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner
origin:origin];
bannerView_.center = CGPointMake(self.view.center.x, self.view.frame.size.height-CGSizeFromGADAdSize(kGADAdSizeBanner).height/2);
bannerView_.adUnitID = @"myid";
bannerView_.rootViewController = self;
[self.view addSubview:bannerView_];
[bannerView_ loadRequest:[GADRequest request]];
}
但是,在iPad,我打算在另一个位置投放不同的广告。因此,我需要在 iPad 中隐藏此广告。我可以这样做吗?
试试这个
bannerView_.hidden=true;
您不需要创建多个横幅视图。更简单的解决方案是使用相同的横幅视图,但在定位视图之前检查当前设备习惯用法。例如,这里是您提供的修改后的代码,用于检查用户使用的是哪个设备:
- (void) webViewDidFinishLoad: (UIWebView*) webView
{
CGPoint origin = CGPointMake(0.0,
self.view.frame.size.height -
CGSizeFromGADAdSize(kGADAdSizeBanner).height);
bannerView_ = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner
origin:origin];
bannerView_.center = CGPointMake(self.view.center.x, self.view.frame.size.height-CGSizeFromGADAdSize(kGADAdSizeBanner).height/2);
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
// Change the banner's center/origin here for the iPad.
}
bannerView_.adUnitID = @"myid";
bannerView_.rootViewController = self;
[self.view addSubview:bannerView_];
[bannerView_ loadRequest:[GADRequest request]];
}