How to make a blinking (or flashing) cursor on iphone?

后端 未结 5 1242
抹茶落季
抹茶落季 2020-12-12 17:43

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

5条回答
  •  孤城傲影
    2020-12-12 18:19

    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)
    }
    

提交回复
热议问题