UIGestureRecognizer阻塞表视图滚动 [英] UIGestureRecognizer blocking table view scrolling
问题描述
我使用自定义 UIGestureRecognizer
子类来跟踪我的 InfoView
类上的手势。 InfoView
类是一个定制 UITableViewCell
子类的子视图 InfoCell
。
我已经将我的手势识别器添加到我的根视图(屏幕上其他一切的父视图,因为我的自定义手势识别器的目的是允许拖动 InfoCell
表之间的视图)。现在,一切都工作,因为它应该,除了一件事。我在 UIGestureRecognizer
子类中使用以下代码来检测 InfoView
视图上的触摸:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UIView * touchView = [[touches anyObject ] view];
if([touchView isKindOfClass:[InfoView class]]){
// Do stuff
}
这里的问题是 InfoView
对象的触摸被拦截,因此它们不会被转发到其中包含
InfoCell
的 InfoView
的父视图。这意味着我不能再通过拖动 InfoView
视图来滚动表视图,这是一个问题,因为 InfoView
覆盖整个 InfoCell
。
有什么方法可以将触摸转移到表视图,可以滚动?我已经尝试了一堆事情:
[super touchesBegan:touches withEvent:event];
p>
[touchView.superview.superview touchesBegan:touches withEvent:event];
( touchView.superview .superview
获得对其父项的引用 UITableView
)
远。此外,我的 UIGestureRecognizer
的 cancelsTouchesInView
属性设置为 NO
,以便不干扰触摸。
帮助感谢。感谢!
我在 touchesBegan
姿势识别器的状态
属性为 UIGestureRecognizerStateBegan
。删除此行似乎可以解决问题。
I'm using a custom UIGestureRecognizer
subclass to track gestures on my InfoView
class. The InfoView
class is a subview of a custom UITableViewCell
subclass called InfoCell
.
I've added my gesture recognizer to my root view (the parent view of everything else on screen, because the purpose of my custom gesture recognizer is to allow dragging of InfoCell
views between tables). Now, everything works as it should except one thing. I'm using the following code in my UIGestureRecognizer
subclass to detect touches on the InfoView
view:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UIView *touchView = [[touches anyObject] view];
if ([touchView isKindOfClass:[InfoView class]]) {
// Do stuff
}
The problem here is that the touches on the InfoView
object are being intercepted, therefore they are not being forwarded to the UITableView
which contains the InfoCell
, which is the parent view of the InfoView
. This means that I can no longer scroll the table view by dragging on the InfoView
view, which is an issue because the InfoView
covers the entire InfoCell
.
Is there any way I can forward the touches onto the table view so that it can scroll? I've tried a bunch of things already:
[super touchesBegan:touches withEvent:event];
[touchView.superview.superview touchesBegan:touches withEvent:event];
(touchView.superview.superview
gets a reference to its parent UITableView
)
But nothing has worked so far. Also, the cancelsTouchesInView
propery of my UIGestureRecognizer
is set to NO
, so thats not interfering with the touches.
Help is appreciated. Thanks!
I had a line in my touchesBegan
method that set the state
property of the gesture recognizer to UIGestureRecognizerStateBegan
. Removing this line seems to fix the problem.
这篇关于UIGestureRecognizer阻塞表视图滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!