I\'m trying to create a custom \"blinking cursor\" in UIKit, I\'ve tried as shown below, having 2 functions that basically keep calling each other until the cursor is hidden
Matt Long's answer in Swift 4:
func addOpacityAnimation(view: UIView) {
let key = "opacity"
let animation = CABasicAnimation(keyPath: key)
animation.fromValue = 1.0
animation.toValue = 0.0
animation.duration = 0.5
animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionLinear)
animation.autoreverses = true
animation.repeatCount = Float.greatestFiniteMagnitude
view.layer.add(animation, forKey: key)
}