iOS-swift3.0 点滴积累:添加手势

2017-07-07  本文已影响0人  xiaopavip

项目中很多时候,都需要用到添加手势。发个

//方法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
上一篇下一篇

猜你喜欢

热点阅读