Skip to content

Instantly share code, notes, and snippets.

@JaviSoto
Created September 10, 2013 22:57
Show Gist options
  • Save JaviSoto/6516942 to your computer and use it in GitHub Desktop.
Save JaviSoto/6516942 to your computer and use it in GitHub Desktop.
iOS 7 Parallax effect
@interface UIView (JSParallaxEffect)
- (void)js_addParallaxEffectWithMaxOffset:(CGFloat)maxOffset;
@end
@implementation UIView (JSParallaxEffect)
- (void)js_addParallaxEffectWithMaxOffset:(CGFloat)maxOffset;
{
UIInterpolatingMotionEffect *parallaxEffectX = [[UIInterpolatingMotionEffect alloc] initWithKeyPath:@"center.x"
type:UIInterpolatingMotionEffectTypeTiltAlongHorizontalAxis];
UIInterpolatingMotionEffect *parallaxEffectY = [[UIInterpolatingMotionEffect alloc] initWithKeyPath:@"center.y"
type:UIInterpolatingMotionEffectTypeTiltAlongVerticalAxis];
parallaxEffectX.minimumRelativeValue = @(-maxOffset);
parallaxEffectX.maximumRelativeValue = @(maxOffset);
parallaxEffectY.minimumRelativeValue = parallaxEffectX.minimumRelativeValue;
parallaxEffectY.maximumRelativeValue = parallaxEffectX.maximumRelativeValue;
UIMotionEffectGroup *effectGroup = [[UIMotionEffectGroup alloc] init];
effectGroup.motionEffects = @[parallaxEffectX, parallaxEffectY];
[self addMotionEffect:effectGroup];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment