Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // ViewController.swift
- // ColorScroll
- //
- // Created by Michael Nino Evensen on 25/09/2019.
- // Copyright © 2019 Michael Nino Evensen. All rights reserved.
- //
- import UIKit
- class ViewController: UIViewController {
- @IBOutlet weak var colorView: UIView!
- var animator: UIViewPropertyAnimator!
- override func viewDidLoad() {
- super.viewDidLoad()
- // Initial Color
- colorView.backgroundColor = .red
- // Setup animation
- self.animator = UIViewPropertyAnimator(duration: 1.0, curve: .easeOut) { [unowned self] in
- self.colorView.backgroundColor = .green
- }
- }
- }
- extension ViewController: UIScrollViewDelegate {
- func scrollViewDidScroll(_ scrollView: UIScrollView) {
- let delta = min(max(0, scrollView.contentOffset.y / self.view.frame.size.height), 1)
- self.animator.fractionComplete = delta
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement