Skip to content

Instantly share code, notes, and snippets.

@greggjaskiewicz
Created September 7, 2016 09:19
Show Gist options
  • Save greggjaskiewicz/83ff53b71d8b3070daccbca7f2a31286 to your computer and use it in GitHub Desktop.
Save greggjaskiewicz/83ff53b71d8b3070daccbca7f2a31286 to your computer and use it in GitHub Desktop.
final class PulsatingButton: UIButton {
   private var timer: Timer?
   func setup() {
       self.layer.shouldRasterize = true
       self.timer = Timer.scheduledTimer(timeInterval: 5.0, target: self, selector: #selector(timerAction), userInfo: nil, repeats: true)
   }
   private let buttonScaleIdentity = CGAffineTransform.init(scaleX: 1.75, y: 1.75)
   func timerAction(timer: Timer) {
       UIView.animate(withDuration: 0.5, delay: 0.3, options: .curveEaseInOut, animations: {
           self.transform = self.buttonScaleIdentity
       }) { (completed) in
           if (completed) {
               UIView.animate(withDuration: 0.5, delay: 0.3, options: .curveEaseInOut,
                              animations: {
                               self.transform = CGAffineTransform.identity
                   }, completion: { (_) in })
           }
       }
   }
   deinit {
       self.timer?.invalidate()
   }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment