2017-10-18 165 views
1

我想让这个代码产生多个“闪烁”以在倒数结束时通知用户。现在它的工作效果非常好,但我理想中有三个。我试着复制代码并将函数放入循环中无济于事。如何让闪烁的屏幕闪烁_ swift 3

在此先感谢您的帮助!

// 闪光灯功能

func flash() { 
    if let wnd = self.view{ 

     var v = UIView(frame: wnd.bounds) 
     v.backgroundColor = UIColor.black 
     v.alpha = 1 

     wnd.addSubview(v) 
     UIView.animate(withDuration: 1.618, animations: { 
      v.alpha = 0.0 
     }, completion: {(finished:Bool) in 
      print("inside") 
      v.removeFromSuperview() 
     }) 
    } 
} 

// 使用闪光灯功能

if (heatUpSeconds == 0) { 
     heatUpTimer.invalidate() 
     // testing screen flashing ideas here cameraView.frame 

     flash() 
+2

刚刚从完成块再次拨打您的闪光功能。使用计数器记录您已经闪现了多少次。 –

回答

-1
var timer:Timer! 

timer = Timer.scheduledTimer(timeInterval: delayBetweenFlashes, target: self, selector: #selector(self.flash), userInfo: nil, repeats: true) 
+3

请在您的回答中添加简短的解释。 –

+0

我不确定你如何初始化你的计时器,你确定“重复”是真的吗?一些开发人员错误地以错误的方式初始化定时器对象,它永远不会触发,或者触发但不会重复。你有重复使用我的代码吗? –