swift cell自定义左滑手势处理方法-kb88凯时官网登录

来自:网络
时间:2023-07-25
阅读:

swift cell自定义左滑手势处理,代码如下所示:

public override init(style: uitableviewcell.cellstyle, reuseidentifier: string?) {
        super.init(style: style, reuseidentifier: reuseidentifier)
        initui()
        makerlayout()
        /// 直接调用手势方法-手势添加在了contentview上
        makerpang()
    }
 private func makerpang(){
        let p = uipangesturerecognizer(target: self,action: #selector(pangaction(_:)))
        p.delegate = self
        contentview.addgesturerecognizer(p)
    }
    
    @objc func pangaction(_ guest: uipangesturerecognizer){
        let state = guest.state
        let x = guest.location(in: self).x
        if state == .began{
            startp = x-conview.mm_x
        }else{
            let gap = x-startp
            if state == .changed{
                if gap<0 {
                    conview.mm_x = max(x-startp, -140)
                }else{
                    conview.mm_x = gap
                }
            }else{
                uiview.animate(withduration: 0.2) {
                    self.conview.mm_x = gap <= -70 ? -140 : 0
                }
            }
        }
    }

swift cell自定义左滑手势处理方法

返回顶部
顶部
网站地图