Advertisement
Guest User

Untitled

a guest
Oct 13th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. //
  2. // ViewController.swift
  3. // ColorScroll
  4. //
  5. // Created by Michael Nino Evensen on 25/09/2019.
  6. // Copyright © 2019 Michael Nino Evensen. All rights reserved.
  7. //
  8.  
  9. import UIKit
  10.  
  11. class ViewController: UIViewController {
  12.  
  13. @IBOutlet weak var colorView: UIView!
  14. var animator: UIViewPropertyAnimator!
  15.  
  16. override func viewDidLoad() {
  17. super.viewDidLoad()
  18.  
  19. // Initial Color
  20. colorView.backgroundColor = .red
  21.  
  22. // Setup animation
  23. self.animator = UIViewPropertyAnimator(duration: 1.0, curve: .easeOut) { [unowned self] in
  24. self.colorView.backgroundColor = .green
  25. }
  26. }
  27. }
  28.  
  29. extension ViewController: UIScrollViewDelegate {
  30. func scrollViewDidScroll(_ scrollView: UIScrollView) {
  31.  
  32. let delta = min(max(0, scrollView.contentOffset.y / self.view.frame.size.height), 1)
  33. self.animator.fractionComplete = delta
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement