我正在尝试使 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/