項(xiàng)目地址: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 {
// 發(fā)送錄音
}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
}
}