Created
          March 31, 2016 04:01 
        
      - 
      
- 
        Save Jesse-calkin/5ded71b68f578f441c95a4e92d05fa76 to your computer and use it in GitHub Desktop. 
    UIMotionEffect Extensions
  
        
  
    
      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
    
  
  
    
  | // | |
| // UIMotionEffectExtensions.swift | |
| // Collection Views | |
| // | |
| // Created by jesse calkin on 3/30/16. | |
| // Copyright © 2016 Shoshin Boogie. All rights reserved. | |
| // | |
| import UIKit | |
| extension UIMotionEffect { | |
| /** | |
| Creates a `UIInterpolatingMotionEffect` for both `x` and `y` axis. | |
| - parameter offset: `CGSize` for the amount of offset to be applied on the `x` and `y` axis when tilting the device. | |
| */ | |
| class func tiltEffect(offset: CGSize) -> UIMotionEffect { | |
| let horizontalEffect = UIInterpolatingMotionEffect(keyPath: "center.x", type: UIInterpolatingMotionEffectType.TiltAlongHorizontalAxis) | |
| horizontalEffect.minimumRelativeValue = offset.width * -1 | |
| horizontalEffect.maximumRelativeValue = offset.width | |
| let verticalEffect = UIInterpolatingMotionEffect(keyPath: "center.y", type: UIInterpolatingMotionEffectType.TiltAlongVerticalAxis) | |
| verticalEffect.minimumRelativeValue = offset.height * -1 | |
| verticalEffect.maximumRelativeValue = offset.height | |
| let effectGroup = UIMotionEffectGroup() | |
| effectGroup.motionEffects = [horizontalEffect, verticalEffect] | |
| return effectGroup | |
| } | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment