0

我在 UIView 的子视图中遇到手势识别问题。我的子视图是一个可通过 UIPanGestureRecognizer 拖动的视图 - 我知道这部分有效。但我在首先接触到那个视图时遇到了问题。触动的是我的 UIView - 而不是我希望他们去的子视图。我尝试使用以下代码将触摸强制重定向到我的目标视图:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    NSLog(@"rT");
    [self.valueLabel touchesBegan:touches withEvent:event];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    NSLog(@"mT");
    [self.valueLabel touchesMoved:touches withEvent:event];
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    NSLog(@"eT");
    [self.valueLabel touchesEnded:touches withEvent:event];
}

...但后来我的控制台发疯了 - 无限循环

...
2013-02-08 17:07:33.683 Totalizer[3810:907] rT
2013-02-08 17:07:33.684 Totalizer[3810:907] rT
2013-02-08 17:07:33.685 Totalizer[3810:907] rT
2013-02-08 17:07:33.686 Totalizer[3810:907] rT
2013-02-08 17:07:33.686 Totalizer[3810:907] rT
2013-02-08 17:07:33.687 Totalizer[3810:907] rT
2013-02-08 17:07:33.688 Totalizer[3810:907] rT
2013-02-08 17:07:33.689 Totalizer[3810:907] rT
2013-02-08 17:07:33.690 Totalizer[3810:907] rT
2013-02-08 17:07:33.691 Totalizer[3810:907] rT
2013-02-08 17:07:33.692 Totalizer[3810:907] rT
2013-02-08 17:07:33.692 Totalizer[3810:907] rT
2013-02-08 17:07:33.693 Totalizer[3810:907] rT
2013-02-08 17:07:33.694 Totalizer[3810:907] rT
2013-02-08 17:07:33.695 Totalizer[3810:907] rT
2013-02-08 17:07:33.696 Totalizer[3810:907] rT
2013-02-08 17:07:33.697 Totalizer[3810:907] rT
2013-02-08 17:07:33.698 Totalizer[3810:907] rT
2013-02-08 17:07:33.700 Totalizer[3810:907] rT
2013-02-08 17:07:33.701 Totalizer[3810:907] rT
2013-02-08 17:07:33.702 Totalizer[3810:907] rT
2013-02-08 17:07:33.703 Totalizer[3810:907] rT
2013-02-08 17:07:33.704 Totalizer[3810:907] rT
2013-02-08 17:07:33.705 Totalizer[3810:907] rT
2013-02-08 17:07:33.706 Totalizer[3810:907] rT
2013-02-08 17:07:33.707 Totalizer[3810:907] rT
2013-02-08 17:07:33.708 Totalizer[3810:907] rT
2013-02-08 17:07:33.709 Totalizer[3810:907] rT
2013-02-08 17:07:33.710 Totalizer[3810:907] rT
2013-02-08 17:07:33.711 Totalizer[3810:907] rT
2013-02-08 17:07:33.713 Totalizer[3810:907] rT
...

我似乎无法弄清楚这一点。

任何事情都有帮助(在合理范围内......)

尔威软件

4

2 回答 2

1

您发布的代码进入循环,因为

valueLabel不响应touchesBegan:, touchesMoved:, 和touchesEnded:... 这调用会回溯到您的代码。

这是一个无意的递归循环。

绝对放弃这种方法。你试过valueLabel.userInteractionEnabled = YES吗?

于 2013-02-09T00:30:02.443 回答
1

您的触摸被转发到 self.label 的 superview,即 self。这导致了无限递归。

于 2013-02-09T00:30:09.643 回答