Skip to content

Instantly share code, notes, and snippets.

@mxcl
Created March 24, 2015 17:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mxcl/2102a833a33e25b382be to your computer and use it in GitHub Desktop.
Save mxcl/2102a833a33e25b382be to your computer and use it in GitHub Desktop.
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
float y = scrollView.contentOffset.y;
////// parallax
CGAffineTransform transform;
BOOL clip = YES;
y -= 320;
if (y < -320) {
float const required_scale = y / -320;
transform = CGAffineTransformMakeTranslation(0, (y+320.f)/2.f);
transform = CGAffineTransformScale(transform, required_scale, required_scale);
clip = NO;
} else
transform = CGAffineTransformMakeTranslation(0, (y+320.f)*3.f/5.f);
stretchyView.transform = transform;
stretchyView.superview.clipsToBounds = clip;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment