iphoneのホーム画面のように、デバイスを傾けたら、背景の画像も動く
iphoneのホーム画面のように、デバイスを傾けたら、背景の画像も動いて傾くっていうものを実装。
注意:imageViewは、画面のサイズよりも若干大きく設定をしておく
x方向の指定 let xMotionEffect = UIInterpolatingMotionEffect(keyPath: "center.x", type: .TiltAlongHorizontalAxis) xMotionEffect.minimumRelativeValue = -10.0 xMotionEffect.maximumRelativeValue = 10.0 y方向の指定 let yMotionEffect = UIInterpolatingMotionEffect(keyPath: "center.y", type: .TiltAlongVerticalAxis) yMotionEffect.minimumRelativeValue = -10.0 yMotionEffect.maximumRelativeValue = 10.0 let motionEffectGroup = UIMotionEffectGroup() motionEffectGroup.motionEffects = [xMotion, yMotion] // imageViewにセットする self.backgroundImageView.addMotionEffect(motionEffectGroup)