ここでスタックオーバーフローに関するこのトピックのすべての質問を検索しましたが、すべてを正しく行っているように見えるため、まだこのエラーが発生します。ボタンが押されている限り記録する、チャットの記録ボタンを実装しようとしています。[HenrysApp.ChatViewController longPress :]: 認識されないセレクターがインスタンス 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()
}
}