Skip to content

Instantly share code, notes, and snippets.

@uruly
Created April 10, 2018 23:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uruly/f29c8a24447b700ade10963a4206c839 to your computer and use it in GitHub Desktop.
Save uruly/f29c8a24447b700ade10963a4206c839 to your computer and use it in GitHub Desktop.
import UIKit
class ButtonTestViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let btn = UIButton()
let btnImg = UIImage(named:"image.png")
btn.frame = CGRect(x:50,y:50,width:120,height:100)
btn.setImage(btnImg, for: .normal)
btn.addTarget(self, action: #selector(self.btnTapped(sender:)), for: .touchUpInside)
self.view.addSubview(btn)
}
@objc func btnTapped(sender:UIButton){
let rotationAnimation = CABasicAnimation(keyPath:"transform.rotation.z")
rotationAnimation.toValue = CGFloat.pi * 2
rotationAnimation.duration = 0.8
rotationAnimation.repeatCount = 1
sender.layer.add(rotationAnimation, forKey: "rotationAnimation")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment