Advertisement
Guest User

Untitled

a guest
Aug 20th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. class CoinView: UIViewController, CAAnimationDelegate {
  2.  
  3. @IBOutlet weak var coinImageView: UIImageView!
  4. let coinProvider = CoinSideProvider()
  5.  
  6. override func viewDidLoad() {
  7. super.viewDidLoad()
  8. let flipCoin = UIPanGestureRecognizer(target: self, action: #selector(flippCoinPan))
  9.  
  10. coinImageView .addGestureRecognizer(flipCoin )
  11. }
  12.  
  13. @objc func flippCoinPan(recognizer: UIPanGestureRecognizer) {
  14. if recognizer.state == .began {
  15. print("dgdf")
  16. coinImageView.image = #imageLiteral(resourceName: "coinSide.png")
  17.  
  18. rotateCoin()
  19. }
  20.  
  21. }
  22.  
  23. func rotateCoin() {
  24. let rotateAnimation = CABasicAnimation()
  25. rotateAnimation.keyPath = "transform.rotation"
  26. rotateAnimation.fromValue = 0
  27. rotateAnimation.toValue = 4 * Double.pi
  28. rotateAnimation.duration = 0.4
  29. rotateAnimation.isRemovedOnCompletion = false
  30. rotateAnimation.delegate = self
  31.  
  32. coinImageView.layer.add(rotateAnimation,
  33. forKey: nil)
  34. }
  35. func animationDidStop(_ anim: CAAnimation, finished flag: Bool) {
  36. coinImageView.image = coinProvider.randomCoinSide()
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement