为什么展示 Google 插页式广告会改变导航栏的高度?Xcode 11.3,iOS 13



每当用户点击打印按钮时,我都会尝试在我的应用中显示插页式广告 - 但在关闭广告后,我的导航栏的高度从 44 增加到 96(在 iPhone 11 Pro Max 物理测试设备上(。 iPhone 8 和 iPhone 11 Pro Max 的模拟器中也会出现相同的行为。

我想知道为什么会发生这种情况 - 以及如何防止它发生。 大约在高度变化的同时,日志中出现了一条警告消息(见下文(,但我不确定该警告是否与我的导航栏问题(或如何防止它(有关。 广告成功展示。

如果我设置了"myProfile.disableAds = true",下面显示的displayInterstitialAd((函数不会运行,广告不会显示,导航栏高度也不会改变。

这是我的代码:

func createAndLoadInterstitial() -> GADInterstitial {
var interstitial = GADInterstitial(adUnitID: adUnitInterstitialID)
interstitial.delegate = self
interstitial.load(GADRequest())
print("Loading interstitial...")
return interstitial
}
func displayInterstitialAd() {
if interstitial.isReady && myProfile.disableAds == false {
print("Debug:  Interstitial:  NavBarFrame: (navigationController?.navigationBar.frame)")
interstitial.present(fromRootViewController: self)
print("Debug:  Interstitial:  NavBarFrame: (navigationController?.navigationBar.frame)")
}
}

func interstitialDidDismissScreen(_ ad: GADInterstitial) {
print("Debug:  InterstitialDelegateDidDismiss:  NavBarFrame: (navigationController?.navigationBar.frame)")
print("interstitialDidDismissScreen")
interstitial = createAndLoadInterstitial() 
}

这是输出:

Print Button tapped...Showing interstitial ad...
Debug:  Interstitial:  NavBarFrame: Optional((0.0, 44.0, 414.0, 44.0))
interstitialWillPresentScreen
Debug:  InterstitialDelegateWillPresent:  NavBarFrame: Optional((0.0, 44.0, 414.0, 44.0))
Debug:  Interstitial:  NavBarFrame: Optional((0.0, 44.0, 414.0, 44.0))
interstitialWillDismissScreen
2020-01-23 08:36:16.387071-0500 MyApp[53938:23813577] [View] First responder error: non-key window attempting reload - allowing due to manual keyboard (first responder window is <UIWindow: 0x101c4ca10; frame = (0 0; 414 896); hidden = YES; gestureRecognizers = <NSArray: 0x28380a880>; layer = <UIWindowLayer: 0x2836f10a0>>, key window is <UIWindow: 0x101c26b50; frame = (0 0; 414 896); gestureRecognizers = <NSArray: 0x2838e9860>; layer = <UIWindowLayer: 0x28368a8a0>>)
Debug:  InterstitialDelegateDidDismiss:  NavBarFrame: Optional((0.0, 44.0, 414.0, 96.0))
interstitialDidDismissScreen
Loading interstitial...

这花了几天时间——但我想通了。

在关闭模式全屏插页式广告后,我的导航栏正在重新生成。 我的 viewDidLoad 为 NavigationBar.appearance(( 设置了"prefersLargeTitles=true"。 我(错误地(认为这已经应用于导航栏,但显然它仅适用于新生成的导航栏。 这就是身高意外变化的原因。 完全是我的错。 很抱歉浪费大家的时间。

最新更新