Last active
April 14, 2019 18:08
-
-
Save maciekish/ecb670b9398d47bdf196 to your computer and use it in GitHub Desktop.
Easy UIInterpolatingMotionEffect. Learn more: http://hack.swic.name/easy-uiinterpolatingmotioneffect
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
// | |
// NaturalMotion.swift | |
// | |
// Created by Maciej Swic on 2014-06-06. | |
// Released under the MIT license. | |
// | |
import UIKit | |
extension UIView { | |
func addNaturalOnTopEffect(maximumRelativeValue : Float = 20.0) { | |
//Horizontal motion | |
var motionEffect = UIInterpolatingMotionEffect(keyPath: "center.x", type: .TiltAlongHorizontalAxis); | |
motionEffect.minimumRelativeValue = maximumRelativeValue; | |
motionEffect.maximumRelativeValue = -maximumRelativeValue; | |
addMotionEffect(motionEffect); | |
//Vertical motion | |
motionEffect = UIInterpolatingMotionEffect(keyPath: "center.y", type: .TiltAlongVerticalAxis); | |
motionEffect.minimumRelativeValue = maximumRelativeValue; | |
motionEffect.maximumRelativeValue = -maximumRelativeValue; | |
addMotionEffect(motionEffect); | |
} | |
func addNaturalBelowEffect(maximumRelativeValue : Float = 20.0) { | |
addNaturalOnTopEffect(maximumRelativeValue: -maximumRelativeValue) | |
} | |
} |
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
// | |
// UIView+NaturalMotion.h | |
// | |
// Created by Maciej Swic on 30/04/14. | |
// Released under the MIT license. | |
// | |
#import <UIKit/UIKit.h> | |
@interface UIView (NaturalMotion) | |
+ (void)addNaturalOnTopEffectWithMaximumRelativeValue:(CGFloat)maximumRealtiveValue; | |
+ (void)addNaturalBelowEffectWithMaximumRelativeValue:(CGFloat)maximumRealtiveValue; | |
@end |
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
// | |
// UIView+NaturalMotion.m | |
// | |
// Created by Maciej Swic on 30/04/14. | |
// Released under the MIT license. | |
// | |
#import "UIView+NaturalMotion.h" | |
@implementation UIView (NaturalMotion) | |
+ (void)addNaturalOnTopEffectWithMaximumRelativeValue:(CGFloat)maximumRealtiveValue { | |
UIInterpolatingMotionEffect* motionEffect = [[UIInterpolatingMotionEffect alloc] initWithKeyPath:@"center.x" type:UIInterpolatingMotionEffectTypeTiltAlongHorizontalAxis]; | |
motionEffect.minimumRelativeValue = @(maximumRealtiveValue); | |
motionEffect.maximumRelativeValue = @(-maximumRealtiveValue); | |
[self addMotionEffect:motionEffect]; | |
motionEffect = [[UIInterpolatingMotionEffect alloc] initWithKeyPath:@"center.y" type:UIInterpolatingMotionEffectTypeTiltAlongVerticalAxis]; | |
motionEffect.minimumRelativeValue = @(maximumRealtiveValue); | |
motionEffect.maximumRelativeValue = @(-maximumRealtiveValue); | |
[self addMotionEffect:motionEffect]; | |
} | |
+ (void)addNaturalBelowEffectWithMaximumRelativeValue:(CGFloat)maximumRealtiveValue { | |
UIInterpolatingMotionEffect* motionEffect = [[UIInterpolatingMotionEffect alloc] initWithKeyPath:@"center.x" type:UIInterpolatingMotionEffectTypeTiltAlongHorizontalAxis]; | |
motionEffect.minimumRelativeValue = @(-maximumRealtiveValue); | |
motionEffect.maximumRelativeValue = @(maximumRealtiveValue); | |
[self addMotionEffect:motionEffect]; | |
motionEffect = [[UIInterpolatingMotionEffect alloc] initWithKeyPath:@"center.y" type:UIInterpolatingMotionEffectTypeTiltAlongVerticalAxis]; | |
motionEffect.minimumRelativeValue = @(-maximumRealtiveValue); | |
motionEffect.maximumRelativeValue = @(maximumRealtiveValue); | |
[self addMotionEffect:motionEffect]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Typo:
realtive
instead ofrelative
.