我在旧项目的主屏幕底部有一个 Google Admob 横幅(用代码创建)。它在所有设备上都能完美运行,除了 Xcode 9 模拟器中的 iPhone X。横幅固定在屏幕的绝对底部,位于主页“按钮”手势区域的后面。我需要它位于底部安全区域之上。
adBannerView.center = CGPoint(x: view.frame.midX, y: view.bounds.height - adBannerView.bounds.height / 2)
如何更改中心点,使横幅底部位于 Home 手势区域上方?
最佳答案
您可以使用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
关于swift - 将 Google Admob 横幅固定到 iPhone X 的底部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46376409/