ios 13 UITableviewCell 左滑删除与UIScrollView滑动手势冲突

问题:横向可滚动的 UIscrollview上面有添加其他VC页面,其中有UITableview
  • 1、创建Scrollview 的子类,实现里面多手势代理方法
class LCCenterScrollView: UIScrollView,UIGestureRecognizerDelegate {
    
    func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
        if gestureRecognizer.state.rawValue != 0 {
            return true
        }
        return false
    }
}
  • 2.实现左滑删除
func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
        if indexPath.section == 0 {
            return true
        }
        return false
    }
    
    func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
        if indexPath.section == 0 , indexPath.row < courses.count {
            let model = courses[indexPath.row]
            let topAction = UITableViewRowAction(style: .default, title: model.isTop ? "取消置顶":"置顶") { [weak self] (rowAction, indexP) in
                guard let `self` = self else {return}
                self.courseTop(model)
            }
            topAction.backgroundColor = MixedColor(styleV: ViewColorSet().V_BBBBBB).unfold()
            let hideAction = UITableViewRowAction(style: .default, title: model.isHided ? "恢复":"隐藏") { [weak self] (rowAction, indexP) in
                guard let `self` = self else {return}
                self.courseHideRequest(model)
            }
            hideAction.backgroundColor = UIColor.zm_color(withHex: 0xff3b3d)
            return [hideAction,topAction]
        }
        return nil
    }
    
  1. 解决左滑 用力过猛 自动调用做右边的Action
 @available(iOS 11.0, *)
    func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
        if indexPath.section == 0 , indexPath.row < courses.count {
            let model = courses[indexPath.row]
            
            let topAction = UIContextualAction(style: .normal, title: model.isTop ? "取消置顶":"置顶") { [weak self] (action, sourceView, complete) in
                guard let `self` = self else {return}
                self.courseTop(model)
                complete(true) // 注意:需要实现这个回调,不然点击后不会自动收缩回去,效果有点僵硬
            }
            
            topAction.backgroundColor = MixedColor(styleV: ViewColorSet().V_BBBBBB).unfold()
            let hideAction = UIContextualAction(style: .normal, title: model.isHided ? "恢复":"隐藏") { [weak self] (action, sourceView, complete) in
                guard let `self` = self else {return}
                self.courseHideRequest(model)
                complete(true)
            }
            hideAction.backgroundColor = UIColor.zm_color(withHex: 0xff3b3d)
            let actions = UISwipeActionsConfiguration(actions: [hideAction,topAction])
            actions.performsFirstActionWithFullSwipe = false
            
            return actions
        }
        return nil
    }

  1. 处理 左滑编辑展开后,向右滑动关闭左滑会触发底部Uiscrollview 页面切换
func tableView(_ tableView: UITableView, willBeginEditingRowAt indexPath: IndexPath) {
        self.superScrollview?.isScrollEnabled = false
}
    
func tableView(_ tableView: UITableView, didEndEditingRowAt indexPath: IndexPath?) {
       self.superScrollview?.isScrollEnabled = true
}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。