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()
上面写了个随机颜色,时间调快一点,就成了屏幕快闪!