How to implement a dynamic background image in fast

I would like to implement the same behavior as the start page with a "true motion background". When you tilt the phone, the background image moves a little, which makes it 3D and “real”.

This is what I would like to do on the application start page.

How to do it?

+4
source share
1 answer

See UIInterpolatingMotionEffect.

You can create one for each axis, create a group and add a group of motion effects UIImageViewin 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)

, y, . x, .

from developer.apple.com/library/ios/documentation/EventHandling/Conceptual/EventHandlingiPhoneOS/motion_event_basics/motion_event_basics.html#//apple_ref/doc/uid/TP40009541-CH6-SW14 ( iOS.)

+6

All Articles