摇一摇

// 实现摇一摇的两种方式
// 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("摇动结束")
    }
}

 

posted @ 2017-02-12 18:34  小课桌  阅读(238)  评论(0编辑  收藏  举报