美文网首页
iOS 传感器

iOS 传感器

作者: 派大星的博客 | 来源:发表于2018-11-12 17:54 被阅读7次

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方向, 屏幕朝下
}
201208272225249957.png

相关文章

网友评论

      本文标题:iOS 传感器

      本文链接:https://www.haomeiwen.com/subject/udztxqtx.html