Skip to content

Instantly share code, notes, and snippets.

@michaelevensen
Last active March 24, 2017 09:44
Show Gist options
  • Save michaelevensen/e7622778ff8bf39fe03f163b7919f426 to your computer and use it in GitHub Desktop.
Save michaelevensen/e7622778ff8bf39fe03f163b7919f426 to your computer and use it in GitHub Desktop.
min()max() Example
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