override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = UIColor(netHex: 0xfc3158)
fadeBackground()
NSTimer.scheduledTimerWithTimeInterval(self.fadeTime, target: self, selector: Selector("fadeBackground"), userInfo: nil, repeats: true)
}
func fadeBackground(){
UIView.animateWithDuration(self.fadeTime, delay: 0, options: UIViewAnimationOptions.AllowUserInteraction, animations: {
var randomIndex = Int(arc4random_uniform(UInt32(CONSTANTS.MainColorScheme.count)))
self.view.backgroundColor = CONSTANTS.MainColorScheme[randomIndex]
}) { (stuff Bool) -> Void in
}
}
我对为什么需要使用[无主自我]有点困惑。 根据这个答案,我应该只使用[无主自我],如果我不在乎在调用闭包时自我仍然存在。 但我从来不明白为什么会这样。为什么我不在乎自己是否在身边? 我希望当闭包被调用时,self 在身边——这就是我在那里写代码的原因。
我在animations
关闭中需要无主自我吗?
在这种情况下,您不需要使用捕获列表,因为两个闭包都是UIView
的,并且不被self
保留。在您的示例中未创建保留周期。