美文网首页
iOS-swift3.0 点滴积累:添加手势

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

作者: xiaopavip | 来源:发表于2017-07-07 11:11 被阅读0次

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

    //方法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
    

    相关文章

      网友评论

          本文标题:iOS-swift3.0 点滴积累:添加手势

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