这篇文章主要介绍了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的字符串与数组求最大值的相关问题讨论 2023-07-22
- R语言-如何切换科学计数法和更换小数点位数 2022-11-23
- R语言关于二项分布知识点总结 2022-11-30
- Go Web开发进阶实战(gin框架) 2023-09-06
- Golang http.Client设置超时 2023-09-05
- R语言绘图数据可视化pie chart饼图 2022-12-10
- Ruby 迭代器知识汇总 2023-07-23
- Swift超详细讲解指针 2023-07-08
- 汇编语言程序设计之根据输入改变屏幕颜色的代码 2023-07-06
- Ruby on Rails在Ping ++ 平台实现支付 2023-07-22
