Created
January 17, 2019 13:52
-
-
Save Aymenworks/c5623e04304203f89ed5889ca3349736 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ViewController: UIViewController { | |
// MARK: Properties | |
@IBOutlet weak var scrollView: UIScrollView! | |
@IBOutlet weak var searchView: SearchView! | |
let goal: CGFloat = 50 | |
var observeScrollViewContentOffset: NSKeyValueObservation? | |
// MARK: Lifecycle | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
observeScrollViewContentOffset = scrollView.observe(\.contentOffset, options: .new) { [weak self] (scrollView, change) in | |
guard let `self` = self, let newValue = change.newValue?.y else { return } | |
var progress = -newValue/self.goal | |
progress = (progress...progress).clamped(to: 0...1).upperBound | |
self.searchView.update(progress: progress) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment