iOS 传感器

1、摇一摇:

import UIKit
import AVFoundation
import AudioToolbox

class GameVC: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        title = "摇动 Demo"
        UIApplication.shared.applicationSupportsShakeToEdit = true
        // Do any additional setup after loading the view.
    }
    
    override func motionBegan(_ motion: UIEvent.EventSubtype, with event: UIEvent?) {
        print("开始摇动的代理方法")
        AudioServicesPlaySystemSound(kSystemSoundID_Vibrate)
    }

    override func motionCancelled(_ motion: UIEvent.EventSubtype, with event: UIEvent?) {
        print("取消摇动的代理方法(一般指的是中途摇动动作被打断)")
    }

    override func motionEnded(_ motion: UIEvent.EventSubtype, with event: UIEvent?) {
        print("结束摇动的代理方法")
    }
}

2、设备方向:

public enum UIDeviceOrientation : Int {
   case unknown
   case portrait // 设备vertically方向, home键在下方
   case portraitUpsideDown // 设备vertically方向, home键在上方
   case landscapeLeft // 设备horizontally方向, home键在右方
   case landscapeRight // 设备horizontally方向, home键在左方
   case faceUp // 设备flat方向, 屏幕朝上
   case faceDown // 设备flat方向, 屏幕朝下
}
iOS 传感器_第1张图片
201208272225249957.png

你可能感兴趣的:(iOS 传感器)