Created
October 18, 2019 07:26
-
-
Save miff/1ef30a3b7ef82230225136ddf3945fc3 to your computer and use it in GitHub Desktop.
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
func addMotion(for view: UIView) { | |
let min: CGFloat = -30 | |
let max: CGFloat = 30 | |
let xMotion = UIInterpolatingMotionEffect(keyPath: "layer.transform.translation.x", type: .tiltAlongHorizontalAxis) | |
xMotion.minimumRelativeValue = min | |
xMotion.maximumRelativeValue = max | |
let yMotion = UIInterpolatingMotionEffect(keyPath: "layer.transform.translation.y", type: .tiltAlongVerticalAxis) | |
yMotion.minimumRelativeValue = min | |
yMotion.maximumRelativeValue = max | |
let motionEffectGroup = UIMotionEffectGroup() | |
motionEffectGroup.motionEffects = [xMotion,yMotion] | |
view.addMotionEffect(motionEffectGroup) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment