我正在使用 AppDelegate 配置横幅视图及其代表。然后在两个 VC 上显示横幅:ViewController 和 SecondViewController。横幅正确显示,但有两个视觉错误。
在应用程序打开时,加载测试横幅大约有 2-3 秒的延迟。当我使用 IB 时,横幅立即出现。
当通过 segue 从 ViewController -> SecondViewController 转换时(呈现模态/全屏/交叉溶解/无动画),在横幅显示之前会有大约 1-2 秒的延迟。
横幅加载完美,减去上面的两个滞后/延迟问题。我该如何解决这些问题?
class AppDelegate: UIResponder, UIApplicationDelegate, GADBannerViewDelegate {
var window: UIWindow?
var adBannerView = GADBannerView()
let myBannerRequest = GADRequest()
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
myBannerRequest.testDevices = [kGADSimulatorID]
adBannerView.delegate = self
adBannerView.isHidden = true
return true
}
func adViewDidReceiveAd(_ bannerView: GADBannerView!) {
adBannerView.isHidden = false
}
func adView(_ bannerView: GADBannerView!, didFailToReceiveAdWithError error: GADRequestError!) {
adBannerView.isHidden = true
}
}
视图控制器
let appDelegate = UIApplication.shared.delegate as! AppDelegate
override func viewDidLoad() {
super.viewDidLoad()
requestAds()
}
internal func requestAds() {
appDelegate.adBannerView = GADBannerView()
appDelegate.adBannerView.adUnitID = "ca-app-pub-3940256099942544/2934735716"
appDelegate.adBannerView.adSize = kGADAdSizeBanner
appDelegate.adBannerView.rootViewController = self
appDelegate.adBannerView.load(appDelegate.myBannerRequest)
appDelegate.adBannerView.center = CGPoint(x: view.frame.midX, y: view.frame.height - appDelegate.adBannerView.frame.height / 2)
view.addSubview(appDelegate.adBannerView)
}
第二视图控制器
// Same as ViewController, with addition of IBAction for the button:
@IBAction func closeButtonPressed(_ sender: UIButton) {
self.dismiss(animated: true, completion: nil)
}