我在这里搜索了有关堆栈溢出的所有问题,但我似乎无法弄清楚,因为我似乎做的一切都是正确的,但我仍然收到这个错误。我正在尝试为我的聊天实现一个录制按钮,只要按下按钮就会录制。我总是收到以下错误: [HenrysApp.ChatViewController longPress:]: unrecognized selector sent to instance 0x7f952602dc00
这是代码:
let longPressGestureRecognizer = UILongPressGestureRecognizer(target: self, action: "longPress:")
longPressGestureRecognizer.minimumPressDuration = 1
self.recordingSession = AVAudioSession.sharedInstance()
do {
try self.recordingSession.setCategory(AVAudioSessionCategoryPlayAndRecord)
try self.recordingSession.setActive(true)
self.recordingSession.requestRecordPermission() { [unowned self] allowed in
DispatchQueue.main.async {
if allowed {
self.record_button.addGestureRecognizer(longPressGestureRecognizer)
} else {
// failed to record!
}
}
}
} catch {
// failed to record!
}
// Gesture Recognizer for the Record Button, so as long as it is pressed, record!
func longPress(longPressGestureRecognizer: UILongPressGestureRecognizer){
if longPressGestureRecognizer.state == .began {
print("long press began")
let recordingTapImage = UIImage(named: "ic_mic_none_white")
record_button.setImage(recordingTapImage, for: .normal)
self.recording()
}
if longPressGestureRecognizer.state == .ended {
print("long press ended")
let recordImage = UIImage(named: "ic_mic_white")
record_button.setImage(recordImage, for: .normal)
self.recordTapRelease()
}
}