Advertisement
Guest User

Untitled

a guest
Jan 19th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 0.70 KB | None | 0 0
  1. // Extension
  2. func motionEffect(intensity: Int) {
  3.  
  4. // Set vertical effect
  5. let verticalMotionEffect = UIInterpolatingMotionEffect(keyPath: "center.y", type: .tiltAlongVerticalAxis)
  6.  
  7. verticalMotionEffect.minimumRelativeValue = -intensity
  8. verticalMotionEffect.maximumRelativeValue = intensity
  9.  
  10. // Set horizontal effect
  11. let horizontalMotionEffect = UIInterpolatingMotionEffect(keyPath: "center.x",
  12. type: .tiltAlongHorizontalAxis)
  13.  
  14. horizontalMotionEffect.minimumRelativeValue = -intensity
  15. horizontalMotionEffect.maximumRelativeValue = intensity
  16.  
  17. // Create group to combine both
  18. let group = UIMotionEffectGroup()
  19. group.motionEffects = [horizontalMotionEffect, verticalMotionEffect]
  20. addMotionEffect(group)
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement