Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Extension
- func motionEffect(intensity: Int) {
- // Set vertical effect
- let verticalMotionEffect = UIInterpolatingMotionEffect(keyPath: "center.y", type: .tiltAlongVerticalAxis)
- verticalMotionEffect.minimumRelativeValue = -intensity
- verticalMotionEffect.maximumRelativeValue = intensity
- // Set horizontal effect
- let horizontalMotionEffect = UIInterpolatingMotionEffect(keyPath: "center.x",
- type: .tiltAlongHorizontalAxis)
- horizontalMotionEffect.minimumRelativeValue = -intensity
- horizontalMotionEffect.maximumRelativeValue = intensity
- // Create group to combine both
- let group = UIMotionEffectGroup()
- group.motionEffects = [horizontalMotionEffect, verticalMotionEffect]
- addMotionEffect(group)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement