ios - UIScrollView 子类从不接收滑动的 touchesBegan 消息

标签 ios uiscrollview touchesbegan

我正在尝试使 ScrollView 只能在特定区域滚动。为此,我继承了 UIScrollView 并重写了 touchesBegan(类似于 this question )。

这是我的(非常简单的)代码。

.h

 @interface SuppressableScrollView : UIScrollView
 @end

.m

#import "SuppressableScrollView.h"

@implementation SuppressableScrollView

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    NSLog(@"touchesBegan touches=%@ event=%@", touches, event);
    [super touchesBegan:touches withEvent:event];
}

@end

touchesBegan 仅在 UIScrollView 通常不使用的触摸(如点击)时被调用。知道如何拦截所有触摸吗?

我想我在某处遗漏了一个概念。

最佳答案

我最近正在研究 UITableViews 的类似内容。 UITableView 是 UIScrollView 的扩展。在深入挖掘它的过程中,我发现有 4 个手势识别器连接到 UIScrollView 以拾取滑动和其他东西。我建议转储手势识别器属性以查看是否有任何被自动创建(我认为它们是)。在这种情况下,我能想到的唯一选择是删除它们,但 ScrollView 将不会响应手势。

因此,您可能需要查看那些手势识别器和手势识别器委托(delegate),看看是否有更好的 Hook 位置。

附言一旦识别出正在进行的手势,手势识别器将自动开始吞咽事件。

关于ios - UIScrollView 子类从不接收滑动的 touchesBegan 消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9523441/

相关文章:

ios - 应用程序保持打开状态时自动锁定功能不起作用 - iOS

ios - 制作自定义导航,最好的方法是什么?

ios - 在运行时获取 UIImageView IB 图像属性值

ios - 切换方向时如何正确定位我的 ScrollView 图像?

ios - UIScrollView 缩小问题(IOS 8 GM)

xcode - 如何结束swift spritekit中的touchesBegan函数

ios - iAd 错误但广告似乎显示正常

swift - iOS 用其他颜色填充 UIBezierPath 的一半而不使用 CAGradientLayer

ios - TouchBegan 在 iOS 12 中被调用,但在 iOS 13 中未被调用

ios - touchesBegan 之后调用的 viewDidLayoutSubviews - 一次又一次