2017-09-23 58 views
2

我在舊項目的主屏幕底部有一個Google Admob橫幅(用代碼創建)。它適用於所有設備,除了Xcode 9模擬器中的iPhone X之外。橫幅固定在屏幕的絕對底部,位於主頁「按鈕」手勢區域後面。我需要它在最低的安全區域之上。將谷歌Admob橫幅固定在iPhone的底部X

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

如何更改中心點,以便橫幅底部位於Home手勢區域之上?

僅供參考,這裏是發生了什麼的屏幕截圖。 Admob banner behind iPhone X home area

回答

2

您可以使用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

+0

每當我試過'NSLayoutConstraint'它給我的錯誤:'型NSException的未捕獲的異常終止' '約束條目必須是UIView或UILayoutGuide的一個實例。' –

+0

@BrunoRecillas您應該創建新的問題並顯示代碼,我會看看它。 – TomSawyer

+0

我有完全相同的錯誤 - 你能解決它還是發佈鏈接到相應的問題? – Yeehaw