简体   繁体   English

iAds Swift app的干扰功能

[英]iAds interfering functionality of Swift app

Since I have enabled iAds in my trivia app, the background, which is supposed to change every time a new question is loaded no longer changes. 由于我在我的琐事应用程序中启用了iAds,因此每次加载新问题时应该更改的背景不再发生变化。 When I comment out the canDisplayBannerAds line, it works again. 当我注释掉canDisplayBannerAds行时,它再次起作用。 Any ideas as to what could be wrong? 关于什么可能是错的任何想法?

import UIKit
import iAd

class ViewController: UIViewController {

    @IBOutlet weak var funFactLabel: UILabel!

    @IBOutlet weak var funFactButton: UIButton!
    let factBook = FactBook()
    let colorWheel = ColorWheel()

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        funFactLabel.text = factBook.randomFact()
        self.canDisplayBannerAds = true
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    @IBAction func showFunFact() {
        let randomColor = colorWheel.randomColor()
        view.backgroundColor = randomColor
        funFactButton.tintColor = randomColor
        funFactLabel.text = factBook.randomFact()
    }

}

Rather than using view.backgroundColor = randomColor you should be using originalContentView.backgroundColor = randomColor 而不是使用view.backgroundColor = randomColor你应该使用originalContentView.backgroundColor = randomColor


How I got the solution: 我是如何得到解决方案的:

From the documentation for canDisplayBannerAds 来自canDisplayBannerAds文档

See Also 也可以看看

originalContentView

And originalContentView says: originalContentView说:

When a view controller enables banner ads, the system puts the view controller's content view inside of a new content view that the system manages. 当视图控制器启用横幅广告时,系统会将视图控制器的内容视图置于系统管理的新内容视图中。 This allows the system to dynamically resize the original content view when a banner ad is displayed, as well as managing the display of the banner ad itself. 这允许系统在显示横幅广告时动态调整原始内容视图的大小,以及管理横幅广告本身的显示。 This property provides access to the original content view, rather than the containing view that manages banner ad display. 此属性提供对原始内容视图的访问,而不是管理横幅广告显示的包含视图。

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

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