我希望在我的应用中添加 AdMob 横幅。我已将它们放置在每个屏幕的底部,它可以正常工作,但在 UIViewControllers 中并不完全。
当我将添加到 UITableViewController 上时,它从屏幕底部的正确位置开始,但是当我滚动表格时,它会随之移动。当我滚动表格时,我需要广告静态停留在屏幕底部。
这是我的代码:
- (void)displayGAD
{
// The frame of the banner is initialized off screen.
// If an ad loads then it will animate onto the screen.
self.bannerView = [[GADBannerView alloc] initWithFrame:CGRectMake(0.0,
self.view.frame.size.height,
GAD_SIZE_320x50.width,
GAD_SIZE_320x50.height)];
self.bannerView.adUnitID = self.adUnitID;
self.bannerView.delegate = self;
self.bannerView.rootViewController = self;
[self.view addSubview:self.bannerView];
[self.bannerView loadRequest:[self createRequest]];
}
- (GADRequest *)createRequest
{
GADRequest *request = [GADRequest request];
#warning Comment this out before distribution
request.testDevices = [NSArray arrayWithObjects:@"84ea3d9789cabb0a34176cbb52c0f992", @"abf08fe141b95987d27ac068602605b8", GAD_SIMULATOR_ID, nil];
return request;
}
- (void)adViewDidReceiveAd:(GADBannerView *)view
{
NSLog(@"Received Ad");
[UIView animateWithDuration:1.0 animations:^ {
view.frame = CGRectMake(0.0,
self.view.frame.size.height - view.frame.size.height,
view.frame.size.width,
view.frame.size.height);
}];
}
- (void)adView:(GADBannerView *)view didFailToReceiveAdWithError:(GADRequestError *)error
{
NSLog(@"Failed to receive ad with error: %@", [error localizedFailureReason]);
}
我已经看到了多个关于如何将广告嵌入到表格视图中的示例,但没有具体说明我想要如何做到这一点。我读到的唯一关于此的内容是我应该将表格视图放入容器视图中,然后将广告也添加到其中。不过,我不知道该怎么做,因为这是一个 UITableViewController。