Parallax background / Accelerometer

func parallaxMotion() { 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] self.ivBackground.addMotionEffect(motionEffectGroup) }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.