【问题标题】:AdMob iOS banner offset issueAdMob iOS 横幅偏移问题
【发布时间】:2026-01-03 17:00:02
【问题描述】:

我已经下载了最新的 iOS 版 AdMob SDK,但我的横幅偏移有问题,如下图所示

这里是我用来显示定位的代码

bannerView = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner]; // kGADAdSizeSmartBannerPortrait

CGRect bannerFrame = bannerView.frame;
bannerFrame.origin.y = [[UIScreen mainScreen] bounds].size.height - bannerFrame.size.height;
[bannerView setFrame:bannerFrame];
bannerView.adUnitID = AD_NOB_BANNER_UNIT_ID;
bannerView.rootViewController = self;
[self.view addSubview:bannerView];

[bannerView loadRequest:[GADRequest request]];

我已将背景颜色设置为绿色,将横幅背景颜色设置为灰色,以检查框的位置是否正确。方框位置正确 {{0, 430}, {320, 50}},但横幅的偏移量错误。

如果我在它上面移动手指,我可以向上滚动它,它会适合屏幕...但是它的偏移不正确,如果我再次向下滚动,我会看到同样的偏移问题。 显然我还没有找到任何方法来设置这个偏移量。

有人遇到并解决了同样的问题吗?

【问题讨论】:

  • 现在有同样的问题。在运行 6.9.2 的 iOS

标签: ios admob offset banner


【解决方案1】:

这与在herehere 讨论的iOS 7 问题UIWebView 具有相同的症状。

在创建bannerView之前添加以下代码:

  UIView *view = [[UIView alloc] init];
  [self.view addSubview:view];

或者如果你需要之后再做:

  UIView *view = [[UIView alloc] init];
  [self.view insertSubview:view belowSubview:bannerView];

似乎正在发生的是 iOS 尝试在根视图的最后一个子视图上设置滚动偏移量。添加视图可以防止这种情况发生在您的 bannerView 上。

【讨论】: