はじめに
UIInterpolatingMotionEffectをつかってデバイスの傾きによってViewを動かせたのでメモ
こんな感じに動きます
実装
ストーリーボードでこんな感じでレイアウトを組みます。
中央に配置された赤い色のmotonViewを動かします

ViewContorollerのコード
import UIKit
class ViewController: UIViewController {
    @IBOutlet weak var motionView: UIView! {
        didSet {
            // 水平方向
            let xMotion = UIInterpolatingMotionEffect(keyPath: "center.x", type: UIInterpolatingMotionEffect.EffectType.tiltAlongHorizontalAxis)
            // 左右の動きの幅
            xMotion.minimumRelativeValue = -200.0
            xMotion.maximumRelativeValue = 200.0
            // 垂直方向
            let yMotion = UIInterpolatingMotionEffect(keyPath: "center.y", type: UIInterpolatingMotionEffect.EffectType.tiltAlongVerticalAxis)
            // 上下の動きの幅
            yMotion.minimumRelativeValue = -200.0
            yMotion.maximumRelativeValue = 200.0
            // モーションエフェクトの指定
            motionView.motionEffects = [xMotion, yMotion]
        }
    }
}
これで実機でビルドすればmotionViewがデバイスの傾きによって動きます!!!
参考
[改訂新版]Swiftポケットリファレンス (POCKET REFERENCE)
