How to make UIImageView blink/flash animation infinite?
Use the following code to get image animation like a blink.
Image Blink (Using image view hide/show):-
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
Timer.scheduledTimer(timeInterval: 0.1, target: self, selector: #selector(self.alarmAlertActivate), userInfo: nil, repeats: true)
}
@objc func alarmAlertActivate(){
myImage.isHidden = !myImage.isHidden
}
Image Blink (Using image view alpha):-
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
Timer.scheduledTimer(timeInterval: 0.7, target: self, selector: #selector(self.alarmAlertActivate), userInfo: nil, repeats: true)
}
@objc func alarmAlertActivate(){
UIView.animate(withDuration: 0.7) {
self.alarmImage.alpha = self.alarmImage.alpha == 1.0 ? 0.0 : 1.0
}
}
You could animate the opacity of the image view repeatedly. Something like:
UIView.animate(withDuration: 2.0,
delay: 0,
options: [.repeat, .autoreverse],
animations: { imageView.alpha = 0 }
)