Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class CoinView: UIViewController, CAAnimationDelegate {
- @IBOutlet weak var coinImageView: UIImageView!
- let coinProvider = CoinSideProvider()
- override func viewDidLoad() {
- super.viewDidLoad()
- let flipCoin = UIPanGestureRecognizer(target: self, action: #selector(flippCoinPan))
- coinImageView .addGestureRecognizer(flipCoin )
- }
- @objc func flippCoinPan(recognizer: UIPanGestureRecognizer) {
- if recognizer.state == .began {
- print("dgdf")
- coinImageView.image = #imageLiteral(resourceName: "coinSide.png")
- rotateCoin()
- }
- }
- func rotateCoin() {
- let rotateAnimation = CABasicAnimation()
- rotateAnimation.keyPath = "transform.rotation"
- rotateAnimation.fromValue = 0
- rotateAnimation.toValue = 4 * Double.pi
- rotateAnimation.duration = 0.4
- rotateAnimation.isRemovedOnCompletion = false
- rotateAnimation.delegate = self
- coinImageView.layer.add(rotateAnimation,
- forKey: nil)
- }
- func animationDidStop(_ anim: CAAnimation, finished flag: Bool) {
- coinImageView.image = coinProvider.randomCoinSide()
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement