Skip to content

Instantly share code, notes, and snippets.

@jibla
Last active August 29, 2015 14:15
Show Gist options
  • Select an option

  • Save jibla/c41b63fd4236bb083103 to your computer and use it in GitHub Desktop.

Select an option

Save jibla/c41b63fd4236bb083103 to your computer and use it in GitHub Desktop.
Parallax effect done with few lines in Swift
// in your viewDidLoad() func.
let min = -50.0
let max = 50.0
var leftRight = UIInterpolatingMotionEffect(keyPath: "center.x", type: .TiltAlongHorizontalAxis)
leftRight.minimumRelativeValue = min
leftRight.maximumRelativeValue = max
var upDown = UIInterpolatingMotionEffect(keyPath: "center.y", type: .TiltAlongVerticalAxis)
upDown.minimumRelativeValue = min
upDown.maximumRelativeValue = max
yourImageView.addMotionEffect(leftRight)
yourImageView.addMotionEffect(upDown)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment