简体   繁体   English

UITableViewCell向右滑动以触发动作或执行检测

[英]UITableViewCell Swipe right to trigger action or perform segue

I'm using SWTableViewCell for it's swipe left and swipe right menu buttons. 我正在使用SWTableViewCell,因为它向左滑动和向右滑动菜单按钮。 It's working pretty well, I just need to customize the swipe right to trigger an action or perform a segue when the user finished dragging the cell to the right. 它工作得很好,我只需要自定义向右滑动即可在用户完成向右拖动单元格后触发动作或执行搜索。

I have one button on the left side and want the action triggered when the user finishes dragging, as illustrated in the attached image: 我在左侧有一个按钮,希望在用户完成拖动操作时触发操作,如下图所示:

在此处输入图片说明

You have to look into the cell's UIGestureRecognizerDelegate and define the actions you need. 您必须查看单元格的UIGestureRecognizerDelegate并定义所需的操作。 You'd also need to look at the direction of the swipe and the state it finished in. Here's an example from my custom UITableViewCell subclass: 您还需要查看滑动的方向和完成的状态。这是我的自定义UITableViewCell子类的示例:

- (void)_pan:(UIPanGestureRecognizer *)recognizer{

    if (recognizer.state == UIGestureRecognizerStateBegan) {

        if ([self.delegate respondsToSelector:@selector(cellDidBeginPan:)])
            [self.delegate cellDidBeginPan:self];

    } else if (recognizer.state == UIGestureRecognizerStateEnded) {
            if ([self.delegate respondsToSelector:@selector(cellDidEndPan:)])
            [self.delegate cellDidEndPan];
   }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM