Last active
March 24, 2017 09:44
-
-
Save michaelevensen/e7622778ff8bf39fe03f163b7919f426 to your computer and use it in GitHub Desktop.
min()max() Example
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
func scrollViewDidScroll(_ scrollView: UIScrollView) { | |
// Move ContainerView based on pagination from custom pagingScrollView | |
if scrollView == pagingScrollView { | |
// Calculate offset | |
let offset = (self.view.frame.size.height - bottomPeekMargin) - scrollView.contentOffset.y | |
// Overlay value (interpolates between 0.0 and 1.0 for end value) | |
// Note to self: contentOffset divided by endValue (where you end the animation) | |
let overlayAlpha = min(1, max(0, scrollView.contentOffset.y / (self.view.frame.size.height - bottomPeekMargin))) | |
// Set overlay value | |
self.darkOverlayView.alpha = overlayAlpha | |
// Freeze when open | |
if offset >= 0 { | |
// Offset view based on scrollView | |
containerView.frame.origin.y = offset | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment