Swift - 手机摇晃的监测和响应

阅读 61

2022-07-18

import UIKit


class ViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()
}

//开始摇晃
override func motionBegan(motion: UIEventSubtype, withEvent event: UIEvent) {
println("开始摇晃")
}

//摇晃结束
override func motionEnded(motion: UIEventSubtype, withEvent event: UIEvent) {
println("摇晃结束")
}

//摇晃被意外终止
override func motionCancelled(motion: UIEventSubtype, withEvent event: UIEvent) {
println("摇晃被意外终止")
}
}

精彩评论(0)

0 0 举报