Swift3 ios10:
override func viewDidLoad() {
super.viewDidLoad()
self.becomeFirstResponder() // To get shake gesture
}
// We are willing to become first responder to get shake motion
override var canBecomeFirstResponder: Bool {
get {
return true
}
}
// Enable detection of shake motion
override func motionEnded(_ motion: UIEvent.EventSubtype, with event: UIEvent?) {
if motion == .motionShake {
print("Why are you shaking me?")
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…