Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. @IBOutlet var labelMiles: UILabel!
  2. let animationDuration = 1.5
  3. let animationStartDate = Date()
  4.  
  5. @IBAction func accelerateButton(_ sender: UIButton) {
  6. // CAD display here; para animacion de MILES
  7. let cadDisplay = CADisplayLink(target: self, selector: #selector(accelerateButton(_:)))
  8. cadDisplay.add(to: .main, forMode: RunLoop.Mode.default)
  9.  
  10. guard let startValue = self.myCar.miles else { return () }
  11. // myCar.addMiles(addToMiles: 10.0)
  12. let endValue = self.myCar.miles! + 10
  13. let now = Date()
  14. let elapsedTime = now.timeIntervalSince(animationStartDate)
  15. if elapsedTime > animationDuration {
  16. self.labelMiles.text = "(endValue)"
  17. } else {
  18. let percentage = elapsedTime / animationDuration
  19. let value = percentage * (endValue - startValue)
  20. self.labelMiles.text = "(value)"
  21. }
  22.  
  23. /*myCar.acceletate()
  24. updateView()*/
  25. }
  26.  
  27. myCar = Car(miles: 12000.50, tires: 4, model: "SUV Santa Fe", age: 2019, companyName: "Hyundai", color: #colorLiteral(red: 0.05882352963, green: 0.180392161, blue: 0.2470588237, alpha: 1), imageName: UIImage(named: "Hyundai.jpg"))
  28. myGarage.append(myCar)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement