欢迎来到代码驿站!

当前位置:首页 >

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

时间:2022-06-20 10:26:52|栏目:|点击:

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

上一篇:FreeRTOS实时操作系统信号量基础

栏    目:

下一篇:vmware增加新硬盘无需重启即可生效的命令脚本

本文标题:swift cell自定义左滑手势处理方法

本文地址:http://www.codeinn.net/misctech/205397.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有