我似乎无法让运动检测方法与 Swift 2.0/Xcode 7 一起使用。我得到的错误表明:“方法不会覆盖其超类中的任何方法”。我想使用内置的 UIEvent 方法检测各种运动。即摇晃。这是我在课堂上的内容
//this is used for detecting UIEvents i.e. 'Shake'
override func canBecomeFirstResponder() -> Bool {
return true
}
……
override func motionEnded(motion: UIEventSubtype, withEvent event: UIEvent)
{
if motion == .MotionShake && randomNumber == SHAKE
{
print("SHAKE RECEIVED")
correctActionPerformed = true
}
else if motion == .MotionShake && randomNumber != SHAKE
{
print("WRONG ACTION")
wrongActionPerformed = true
}
else
{
print("WRONG ACTION")
wrongActionPerformed = true
}
}
这里遇到了同样的问题:Swift 2 migration questions