Guest User

Untitled

a guest
Nov 18th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. //: Playground - noun: a place where people can play
  2.  
  3. import UIKit
  4.  
  5. let shape = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 100))
  6. shape.backgroundColor = .lightGray
  7. shape.layer.cornerRadius = shape.bounds.height/2
  8.  
  9. let label = UILabel(frame: .zero)
  10. label.font = UIFont.boldSystemFont(ofSize: shape.bounds.height/2)
  11.  
  12. var count = 1
  13. label.text = "\(count)"
  14. label.sizeToFit()
  15.  
  16. let container = UIView(frame: CGRect(x: 0, y: 0, width: 500, height: 200))
  17. container.addSubview(shape)
  18. container.addSubview(label)
  19. container.backgroundColor = .white
  20.  
  21. shape.center = container.center
  22. label.center = shape.center
  23.  
  24. class Bla: NSObject {
  25. @objc func onTap(_ g: UIGestureRecognizer) {
  26.  
  27. let duration: TimeInterval = 0.2
  28. let shrinkTo: CGFloat = 0.5
  29.  
  30. UIView.animate(withDuration: duration, animations: {
  31. UIView.animate(withDuration: 0, delay: 0, options: [.curveEaseIn], animations: {
  32. shape.transform.a = shrinkTo
  33. label.transform.d = 1 - 0.2 * shrinkTo
  34. })
  35. UIView.animate(withDuration: 0, delay: 0, options: [.curveEaseOut], animations: {
  36. label.transform.a = 0.001
  37. label.transform.tx = -shape.bounds.width/2 * shrinkTo + 1
  38. }) { _ in
  39. count+=1
  40. label.text = "\(count)"
  41. label.sizeToFit()
  42. label.transform.tx = -label.transform.tx
  43.  
  44. UIView.animate(withDuration: duration, animations: {
  45. UIView.animate(withDuration: 0, delay: 0, options: [.curveEaseOut], animations: {
  46. shape.transform.a = 1
  47. label.transform.a = 1
  48. })
  49. UIView.animate(withDuration: 0, delay: 0, options: [.curveEaseIn], animations: {
  50. label.transform.d = 1
  51. label.transform.tx = 0
  52. })
  53. })
  54. }
  55. })
  56.  
  57. }
  58. }
  59.  
  60. let a = Bla()
  61. container.addGestureRecognizer(UITapGestureRecognizer(target: a, action: #selector(Bla.onTap(_:))))
  62.  
  63. import PlaygroundSupport
  64. PlaygroundPage.current.liveView = container
  65. PlaygroundPage.current.needsIndefiniteExecution = true
Add Comment
Please, Sign In to add comment