这篇文章主要介绍了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自定义左滑手势处理方法


基础教程推荐
猜你喜欢
- ruby-on-rails-为使用Rails 4,nginx和乘客的用户设置自定义域 2023-09-21
- R语言 ggplot2改变柱状图的顺序操作 2022-11-17
- win10下使用virtualbox + vagrant配置ruby开发机环境 2023-07-23
- R语言-修改(替换)因子变量的元素操作 2022-11-26
- Swift初始化器与可选链的使用方法介绍 2023-07-08
- Ruby3多线程并行Ractor使用方法详解 2023-07-23
- Swift中重写和重载的使用与对比总结 2023-07-05
- 浅析ELF转二进制允许把 Binary 文件加载到任意位置 2023-07-06
- R语言绘制折线图实例分析 2022-11-21
- ruby on rails validates 2023-09-22