ios - 为什么显示 Google 插页式广告会改变我的导航栏的高度? Xcode 11.3、iOS 13

标签 ios swift xcode admob uinavigationbar

每当用户点击打印按钮时,我尝试在我的应用中显示插页式广告 - 但在关闭广告后,我的导航栏的高度从 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”。我(错误地)认为它已经应用于导航栏,但显然它仅适用于新生成的导航栏。 这就是高度意外变化的原因。完全是我的错。抱歉浪费了大家的时间。

关于ios - 为什么显示 Google 插页式广告会改变我的导航栏的高度? Xcode 11.3、iOS 13,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59880491/

相关文章:

javascript - 博览会上传:ios with Release Channels

ios - Swift 上基于流的 JSON 解析

objective-c - 将复杂的 Objective-C 宏转换为 swift

ios - parse.com 需要来自其他表的图像

ios - 在 UITextView 上以编程方式禁用 iOS8 Quicktype 键盘

ios - AFNetworking 3.0 后台上传不工作

swift - 如何仅裁剪 View 的左侧和右侧?

ios - 如何更改 LAContext 的 StatusBar 样式

xcode - AvMutableComposition 出现末尾有黑框的问题

android - React-Native:如何缩放字体大小以支持 Android 和 iOS 中的许多不同分辨率和屏幕?