Created
February 19, 2014 21:32
-
-
Save wavecos/9102074 to your computer and use it in GitHub Desktop.
Add Parallax Effect to View
This file contains hidden or 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
-(void) backgroundParallaxEffect { | |
// Set vertical effect | |
UIInterpolatingMotionEffect *verticalMotionEffect = | |
[[UIInterpolatingMotionEffect alloc] | |
initWithKeyPath:@"center.y" | |
type:UIInterpolatingMotionEffectTypeTiltAlongVerticalAxis]; | |
verticalMotionEffect.minimumRelativeValue = @(-10); | |
verticalMotionEffect.maximumRelativeValue = @(10); | |
// Set horizontal effect | |
UIInterpolatingMotionEffect *horizontalMotionEffect = | |
[[UIInterpolatingMotionEffect alloc] | |
initWithKeyPath:@"center.x" | |
type:UIInterpolatingMotionEffectTypeTiltAlongHorizontalAxis]; | |
horizontalMotionEffect.minimumRelativeValue = @(-10); | |
horizontalMotionEffect.maximumRelativeValue = @(10); | |
// Create group to combine both | |
UIMotionEffectGroup *group = [UIMotionEffectGroup new]; | |
group.motionEffects = @[horizontalMotionEffect, verticalMotionEffect]; | |
// Add both effects to your view | |
// imgBackground is a UIImageView | |
[self.imgBackground addMotionEffect:group]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment