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. When I comment out the canDisplayBannerAds line, it works again. 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
How I got the solution:
From the documentation for canDisplayBannerAds
See Also
originalContentView
And originalContentView says:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With