【发布时间】:2016-11-15 11:10:28
【问题描述】:
我正在使用JSQMessagesViewController 来实现聊天。我添加了一个录制按钮,并希望通过按住该按钮来发送音频消息以录制并通过释放按钮来停止录制。 目前我正在尝试这样做:
record_button = UIButton(type: UIButtonType.custom)
record_button.tintColor = UIColor.white
record_button.setImage(recordImage, for: .normal)
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.addTarget(self, action: #selector(ChatViewController.recording), for: .touchDown )
self.record_button.addTarget(self, action: #selector(ChatViewController.recordTapRelease), for: .touchUpInside)
self.record_button.addTarget(self, action: #selector(ChatViewController.recordTapRelease), for: .touchDragExit)
} else {
// failed to record!
}
}
}
} catch {
// failed to record!
}
不幸的是,它无法正常工作。它仅在我按下按钮向上移动时起作用。只有这样它才能识别保持事件并记录。当我触摸并按住同一位置时,它不会记录,当我释放触摸时,它会发送 1 秒的音频消息。
编辑 我意识到问题在于我的 Collectionview 有一个 ScrollView。 scrollview 会延迟 touchdown 事件以检查用户是否滚动。无论如何我应该如何触发触地事件?
【问题讨论】:
标签: ios swift audio uibutton audio-recording