項目中很多時候,都需要用到添加手勢刃麸。發(fā)個
//方法1
// 先設置要添加手勢的View可交互
withdrawalLabel.isUserInteractionEnabled = true
let tapGesture = UITapGestureRecognizer()
tapGesture.reactive.stateChanged.observeValues { [weak self] _ in
guard let strongSelf = self else {
return
}
strongSelf.withdrawalClosure?(type)
}
withdrawalLabel.addGestureRecognizer(tapGesture)
//方法2
let tap = UITapGestureRecognizer()
tap.addTarget(self, action: #selector(doSthAction(_:)))
tap.delegate = self
withdrawalLabel.addGestureRecognizer(tap)
兩種方法都可以踊餐,方法1需要
import ReactiveCocoa