I would like to implement the same behaviour that the start page with "true motion backgrounds". When you tilt the phone the background image move a bit which makes it look 3D and "real".
This what I would like in my application start page.
How do I make this?
See UIInterpolatingMotionEffect
.
You can create one for each axis, create a group, and add the motion effect group to the UIImageView
in the background.
let horizontalMotionEffect = UIInterpolatingMotionEffect(keyPath: "center.x", type: .TiltAlongHorizontalAxis)
horizontalMotionEffect.minimumRelativeValue = -50
horizontalMotionEffect.maximumRelativeValue = 50
let verticalMotionEffect = UIInterpolatingMotionEffect(keyPath: "center.y", type: .TiltAlongVerticalAxis)
verticalMotionEffect.minimumRelativeValue = -50
verticalMotionEffect.maximumRelativeValue = 50
let motionEffectGroup = UIMotionEffectGroup()
motionEffectGroup.motionEffects = [horizontalMotionEffect, verticalMotionEffect]
imageView.addMotionEffect(motionEffectGroup)
Thus, as you tilt it about the y-axis, the image will move left and right. As you tilt about the x-axis, the image will move up and down.
(Image taken from the Event Handling Guide for iOS.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With