这篇文章主要介绍了swift cell自定义左滑手势处理,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
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自定义左滑手势处理的文章就介绍到这了,更多相关swift cell自定义左滑内容请搜索编程学习网以前的文章希望大家以后多多支持编程学习网!
沃梦达教程
本文标题为:swift cell自定义左滑手势处理方法
基础教程推荐
猜你喜欢
- golang 自然语言处理工具(gohanlp) 2023-09-05
- R语言histogram(直方图)的具体使用 2022-10-28
- R语言关联规则深入详解 2022-11-08
- Go语言实现一个Http Server框架(二) Server的抽象 2023-07-25
- Ruby on Rails在Ping ++ 平台实现支付 2023-07-22
- R语言多元线性回归实例详解 2022-12-15
- ruby-on-rails – Nginx支持的Rails应用程序中缺少Content-Length Header 2023-09-20
- go语言的魔幻旅程14-反射 2023-09-05
- R语言学习代码格式一键美化 2022-12-05
- R语言使用gganimate创建可视化动图 2022-12-10
