Created
September 10, 2013 22:57
-
-
Save JaviSoto/6516942 to your computer and use it in GitHub Desktop.
iOS 7 Parallax effect
This file contains 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
@interface UIView (JSParallaxEffect) | |
- (void)js_addParallaxEffectWithMaxOffset:(CGFloat)maxOffset; | |
@end |
This file contains 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
@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