【问题标题】:UITableView single-gesture row swipe actionsUITableView 单手势行滑动动作
【发布时间】:2016-09-01 15:25:56
【问题描述】:

我正在尝试在我的 UITableView 中实现单手势滑动操作,您可以在其中滑动以显示操作按钮,然后继续一直滑动以激活默认操作(例如“删除”或“标记为已读”在邮件中)。

我正在我的代表中实施-tableView:editActionsForRowAtIndexPath:。我的按钮出现了,当我点击它时它会工作,但它不会被完全滑动激活。

我已经在我的数据源中尝试过使用和不使用-tableView:commitEditingStyle:forRowAtIndexPath:-tableView:canEditRowAtIndexPath:。只有后者被调用,但似乎两者都没有区别。

我还需要做些什么吗?还是使用标准 API 实际上无法实现这种行为?

【问题讨论】:

    标签: ios uitableview


    【解决方案1】:

    我会检查你的手势识别器的目标函数中滑动是否超过了某个阈值。

    试试这个

    func swipeRight(sender: UIGestureRecognizer){
        let threshold : CGFloat = 100;
        var startLocation = CGPoint()
        if (sender.state == UIGestureRecognizerState.Began){
            startLocation = sender.locationInView(self.view)
        }else if (sender.state == UIGestureRecognizerState.Ended){
            let stopLocation = sender.locationInView(self.view)
            let distanceX = stopLocation.x - startLocation.x
            let distanceY = stopLocation.y - startLocation.y
            let distance = sqrt(distanceX*distanceX + distanceY*distanceY )
            if (distance > threshold ){
                //Delete or Edit Row Here
            }
        }
    }
    

    【讨论】:

    • 如果我正在为滑动按钮进行自定义实现。实际上,我正在这样做(基于 MGSwipeTableCell),但我试图看看是否可以用标准 API 替换该方法并摆脱大量代码。使用editActionsForRowAtIndexPath,操作系统完全负责手势识别器。
    猜你喜欢
    • 2023-04-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-04
    • 1970-01-01
    相关资源
    最近更新 更多