繁体   English   中英

为什么显示 Google 插页式广告会改变我的 NavigationBar 的高度? Xcode 11.3,iOS 13

[英]Why does displaying a Google Interstitial Ad change the height of my NavigationBar? 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...

这花了几天 - 但我想通了。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM