且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在其他平移手势后告诉ScrollView滚动

更新时间:2023-01-25 14:39:21

我真的不喜欢 UITableView 但我猜问题是将自定义 UIPanGestureRecognizer 分配给 _tableView 您基本上使默认值无效。无论如何你可以用这种方式解决它。

I'm not really fond on UITableView but I guess the problem is that assigning your custom UIPanGestureRecognizer to _tableView you're basically invalidating the default one. Anyway whatever the reason you can solve it this way.

让我们假设你在ViewController中做了所有事情,即使它很脏。

Let's assume you do everything in the ViewController, even if it's quite dirty.

使您的ViewController符合 UIGestureRecognizerDelegate 协议

Make your ViewController conform the UIGestureRecognizerDelegate protocol

ViewController.m $中c $ c>覆盖 gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:方法。

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
    return YES;
}

正如文档所说:


询问代表是否应允许两个手势识别器同时识别手势。

Asks the delegate if two gesture recognizers should be allowed to recognize gestures simultaneously.

返回值

是的,允许gestureRecognizer和otherGestureRecognizer同时识别他们的手势。默认实现返回NO-没有两个手势可以同时识别。

Return Value
YES to allow both gestureRecognizer and otherGestureRecognizer to recognize their gestures simultaneously. The default implementation returns NO—no two gestures can be recognized simultaneously.

这样你的pan识别器和默认的 UITableView 将运行一个。

This way both your pan recognizer and the default UITableView one will run.

您需要做的最后一件事是将ViewController设置为 UIPanGestureRecognizer

Last thing you need to do is to set the ViewController as the delegate for the UIPanGestureRecognizer:

UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)];
panRecognizer.delegate = self;

注意:这是您可以实施的最重要且最脏的解决方案。更好的解决方案是将手势跟踪逻辑转换为单元格本身,或者将 UIPanGestureRecognizer 子类化。请查看此答案

Note: This is the fastes and dirtiest solution you could implement. A better solution could be to shift the gesture tracking logic into the cell itself, or subclass the UIPanGestureRecognizer. Take a look at this answer too.