How to do a native “Pulse effect” animation on a UIButton - iOS

前端 未结 4 773
梦如初夏
梦如初夏 2020-12-02 04:28

I would like to have some kind of pulse animation (infinite loop \"scale in - scale out\") on a UIButton so it gets users\' attention immediately.

I saw this link Ho

4条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-02 04:59

    Here is the swift code for it ;)

    let pulseAnimation:CABasicAnimation = CABasicAnimation(keyPath: "transform.scale")
    pulseAnimation.duration = 1.0
    pulseAnimation.toValue = NSNumber(value: 1.0)
    pulseAnimation.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeInEaseOut)
    pulseAnimation.autoreverses = true
    pulseAnimation.repeatCount = .greatestFiniteMagnitude
    self.view.layer.add(pulseAnimation, forKey: nil)
    

提交回复
热议问题