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 } } } }
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
评论(0)