项目中很多时候,都需要用到添加手势。发个
//方法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
网友评论