I'm trying to light up a bunch of vibrant UIButton
subclass instances by calling the flash()
method given by:
func flash(delay: TimeInterval = 0.0) {
DispatchQueue.main.asyncAfter(deadline: .now() + delay) { [weak self] in
guard let strongSelf = self else { return }
let flashView = UIView(frame: strongSelf.bounds)
strongSelf.insertSubview(flashView, at: 0)
flashView.backgroundColor = strongSelf.color
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { flashView.removeFromSuperview() }
}
}
Using this function I can for-loop through an array of buttons triggering a flash effect that lasts for 0.1 seconds with the flashing caused by the vibrancy layer altering the flashView
instance behind it.
Does this function have any drawbacks by calling DispatchQueue.main.asyncAfter
within a call to DispatchQueue.main.asyncAfter
?