我想实现与具有“真实运动背景”的起始页相同的行为。当您倾斜手机时,背景图像会稍微移动一点,使其看起来像3D图像和“真实”图像。
这是我在应用程序开始页面中想要的。
我该怎么做?
请参阅UIInterpolatingMotionEffect
。
您可以为每个轴创建一个,创建一个组,然后将运动效果组添加到UIImageView
后台。
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轴倾斜时,图像将上下移动。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句