[我试图在用户点击打印按钮时在我的应用中显示插页式广告-但是在关闭广告后,我的navigationBar的高度已从44增加到96(在iPhone 11 Pro Max物理测试设备上)。 iPhone 8和iPhone 11 Pro Max的模拟器都发生相同的行为。
我想知道为什么会这样-以及如何防止它发生。高度变化的大约同一时间,日志中会出现一条警告消息(见下文),但我不确定该警告是否与我的navigationBar问题有关(或如何防止)。广告展示成功。
如果我设置为“ myProfile.disableAds = true”,则如下所示的displayInterstitialAd()函数不会运行,该广告不会显示,并且NavigationBar的高度不会改变。
这是我的代码:
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...
花了好几天-但我知道了。