Skip to content

Instantly share code, notes, and snippets.

@eddiekaiger
Created December 2, 2014 22:55
Show Gist options
  • Save eddiekaiger/24316e5e0481c898994e to your computer and use it in GitHub Desktop.
Save eddiekaiger/24316e5e0481c898994e to your computer and use it in GitHub Desktop.
Scroll-Based Animation in iOS
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGFloat scrollOffset = scrollView.contentOffset.y;
// Shift dismiss button up on scroll when user is at the top of the scrollview
if (scrollOffset < -[self tableViewOffsetTop]) {
self.dismissButton.transform = CGAffineTransformMakeTranslation(0, scrollOffset + [self tableViewOffsetTop]);
}
// Dismiss after user scrolls down far enough
CGFloat dismissThreshold = -([self tableViewOffsetTop] + 80);
if (scrollOffset < dismissThreshold) {
self.dismissButton.hidden = YES;
[self dismissHotlines];
}
}
- (CGFloat)tableViewOffsetTop
{
return [UIScreen screenHeight] / 4.0f;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment