Created
July 25, 2014 15:23
-
-
Save mlabraca/2e21c0e7dcaa17f092fc to your computer and use it in GitHub Desktop.
UIInterpolatingMotionEffect vertically and horizontally for a view (iOS 7 and later)
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
+ (void) applyMotionEffects:(UIView *)view forMotionEffectExtent:(float)motionEffectExtentOffset | |
{ | |
if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1) { | |
return; | |
} | |
UIInterpolatingMotionEffect *horizontalEffect = [[UIInterpolatingMotionEffect alloc] initWithKeyPath:@"center.x" | |
type:UIInterpolatingMotionEffectTypeTiltAlongHorizontalAxis]; | |
horizontalEffect.minimumRelativeValue = @(-motionEffectExtentOffset); | |
horizontalEffect.maximumRelativeValue = @( motionEffectExtentOffset); | |
UIInterpolatingMotionEffect *verticalEffect = [[UIInterpolatingMotionEffect alloc] initWithKeyPath:@"center.y" | |
type:UIInterpolatingMotionEffectTypeTiltAlongVerticalAxis]; | |
verticalEffect.minimumRelativeValue = @(-motionEffectExtentOffset); | |
verticalEffect.maximumRelativeValue = @( motionEffectExtentOffset); | |
UIMotionEffectGroup *motionEffectGroup = [[UIMotionEffectGroup alloc] init]; | |
motionEffectGroup.motionEffects = @[horizontalEffect, verticalEffect]; | |
[view addMotionEffect:motionEffectGroup]; | |
[horizontalEffect release]; | |
[verticalEffect release]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment