摇一摇

// 实现摇一摇的两种方式
// 1、使用加速计获取加速度数据,自定义一个范围,超过该范围就判定为产生摇动事件
// 2、使用系统封装好的摇动事件

import UIKit

class ViewController: UIViewController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
    }
    
    override func motionBegan(_ motion: UIEventSubtype, with event: UIEvent?) {
        print("开始摇动")
    }
    
    override func motionCancelled(_ motion: UIEventSubtype, with event: UIEvent?) {
        print("摇动被打断")
    }
    
    override func motionEnded(_ motion: UIEventSubtype, with event: UIEvent?) {
        print("摇动结束")
    }
}
原文地址:https://www.cnblogs.com/panda1024/p/6391496.html