Skip to content

Instantly share code, notes, and snippets.

@miff
Created October 18, 2019 07:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miff/1ef30a3b7ef82230225136ddf3945fc3 to your computer and use it in GitHub Desktop.
Save miff/1ef30a3b7ef82230225136ddf3945fc3 to your computer and use it in GitHub Desktop.
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