项目地址:https://github.com/zhuyunlongYL/YLBaseChat
// 录音按钮 添加手势
let touchGestureRecognizer = YLTouchesGestureRecognizer(target: self, action: #selector(YLReplyView.recoverGesticulation(_:)))
// 录音按钮 手势处理
func recoverGesticulation(_ gesticulation:UIGestureRecognizer) {
if gesticulation.state == UIGestureRecognizerState.began {
// 开始录音
}else if gesticulation.state == UIGestureRecognizerState.ended {
let point = gesticulation.location(in: gesticulation.view)
if point.y > 0 {
// 发送录音
}else{
// 取消录音
}
}else if gesticulation.state == UIGestureRecognizerState.changed {
let point = gesticulation.location(in: gesticulation.view)
if point.y > 0 {
// 向上滑动取消录音
}else{
// 松开取消录音
}
}
}
//自定义手势
import Foundation
import UIKit
import UIKit.UIGestureRecognizerSubclass
class YLTouchesGestureRecognizer:UIGestureRecognizer {
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent) {
state = UIGestureRecognizerState.began
}
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent) {
state = UIGestureRecognizerState.changed
}
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent) {
state = UIGestureRecognizerState.ended
}
override func touchesCancelled(_ touches: Set<UITouch>, with event: UIEvent) {
state = UIGestureRecognizerState.ended
}
override func reset() {
state = UIGestureRecognizerState.possible
}
}