1,創建
//控制器 timer = Timer.scheduledTimer(timeInterval: 0.001, target: self, selector: #selector(FifteenthViewController.tickDown), userInfo: nil, repeats: true)
2,方法實現
func tickDown()
{
let a = Int(arc4random()%255)+1
let b = Int(arc4random()%255)+1
let c = Int(arc4random()%255)+1
self.view.backgroundColor = UIColor.init(red: CGFloat(a/255), green: CGFloat(b/255), blue: CGFloat(c/255), alpha: 1.0)
}
3,終止定時器的方法
timer.invalidate()
上面寫了個隨機顏色,時間調快一點,就成了屏幕快閃!