美文网首页
聊天界面 录音按钮的手势识别

聊天界面 录音按钮的手势识别

作者: 朱云龙 | 来源:发表于2017-06-13 09:58 被阅读0次

项目地址: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
    }
    
}

相关文章

网友评论

      本文标题:聊天界面 录音按钮的手势识别

      本文链接:https://www.haomeiwen.com/subject/vzfdqxtx.html