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 } } } }