【问题标题】:Pinning a Google Admob Banner to the bottom of an iPhone X将 Google Admob 横幅固定到 iPhone X 的底部
【发布时间】:2017-09-23 05:34:53
【问题描述】:

我在一个旧项目的主屏幕底部有一个 Google Admob 横幅(用代码创建)。它适用于所有设备,除了 Xcode 9 模拟器中的 iPhone X。横幅固定在屏幕的绝对底部,位于主页“按钮”手势区域的后面。我需要它高于底部安全区域。

adBannerView.center = CGPoint(x: view.frame.midX, y: view.bounds.height - adBannerView.bounds.height / 2)

如何更改中心点,使横幅底部刚好位于 Home 手势区域的上方?

作为参考,这里是正在发生的事情的屏幕截图。

【问题讨论】:

    标签: swift autolayout admob


    【解决方案1】:

    您可以使用 safeAreaLayoutGuide 将底部约束设置为 admob 横幅。

    if #available(iOS 11, *) {
        NSLayoutConstraint(item: admobbanner, attribute: .bottom, relatedBy: .equal, toItem: view.safeAreaLayoutGuide.bottomAnchor, attribute: .bottom, multiplier: 0.0, constant: 0.0)
    }
    

    或者使用 snapkit:

    if #available(iOS 11, *) {
        make.bottom.equalTo(view.safeAreaLayoutGuide.snp.bottomMargin)
    }
    

    它会留下空间 = safeAreaLayoutGuide bottomMargin

    【讨论】:

    • 每当我尝试 NSLayoutConstraint 时,它都会给我错误:terminating with uncaught exception of type NSException Constraint items must each be an instance of UIView, or UILayoutGuide.
    • @BrunoRecillas 你应该创建新问题并显示代码,我会看看它。
    • 我遇到了完全相同的错误 - 您能否解决它或发布相应问题的链接?
    • @Yeehaw 我有同样的错误,你需要使用指南作为输入,而不是 guide.bottomAnchor/others.. 所以 toItem 应该是:self.view.safeAreaLayoutGuide
    • 有谁知道为什么这对 facebook 受众网络不起作用?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多