How can I do that without causing infinite memory issues? I'm trying something like this:
override func viewDidAppear(animated: Bool) {
view.backgroundColor = UIColor.whiteColor()
fadeBackground()
}
let colors = [UIColor.blueColor(), UIColor.redColor(), UIColor.greenColor(), UIColor.orangeColor(), UIColor.purpleColor()]
func fadeBackground(){
UIView.animateWithDuration(4, delay: 0, options: UIViewAnimationOptions.CurveLinear, animations: {
var randomIndex = Int(arc4random_uniform(UInt32(self.colors.count)))
self.view.backgroundColor = self.colors[randomIndex]
}) { (stuff Bool) -> Void in
self.fadeBackground()
}
}
I'm afraid this will eventually eat up the memory. How can I do this without recursion? Do I need [unowned self] ?
I believe that's the right code. Try setting view.backgroundColor to an initial color like UIColor.whiteColor() and try again. Then you can randomly pick another color with arc4random() or something and call the same method.
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