我在手势识别器响应不正确的子视图时遇到问题,怎么办?
我有一个名为 ImageViewController 的父视图。在此视图中,我添加了两个名为 ImageDetailViewController 的子视图。在此详细视图控制器中,我声明了一些手势,这些手势仅需要在各自的视图上执行某些操作。代码如下:
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(changeModeButtonPushed:)];
[tap setNumberOfTapsRequired:2];
[tap setNumberOfTouchesRequired:1];
[tap setDelegate:self];
[openGLView addGestureRecognizer:tap];
[tap release];
UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(touchDidDrag:)];
[panRecognizer setMaximumNumberOfTouches:1];
[openGLView addGestureRecognizer:panRecognizer];
[panRecognizer release];
UIPanGestureRecognizer *shiftRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(shiftView:)];
[shiftRecognizer setMinimumNumberOfTouches:2];
[openGLView addGestureRecognizer:shiftRecognizer];
[shiftRecognizer release];
UIPinchGestureRecognizer *pinchRecog = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(viewPinched:)];
[openGLView addGestureRecognizer:pinchRecog];
[pinchRecog release];
因此,我需要在该父视图内并排加载两个详细视图,然后我需要能够在一个视图或另一个视图上执行这些手势,并让该视图做出响应。
问题是,当我用一根手指平移时,有时它会调用它应该调用的视图,但大多数情况下,它会在另一个视图上触发!这没有任何意义!我已经尝试过调试和我能想到的所有其他方法,但我只是看不出两个单独声明的对象如何像这样混合在一起。
更奇怪的是,有些手势确实可以正常工作。所以只是这个一根手指平移的手势就把一切搞砸了。
我可能会错过什么?我怎样才能调试这个?一切看起来都像是对象确实是分开的,但它们只是没有那样表现......
I have a parent view called ImageViewController. To this view I add up to two subviews called ImageDetailViewController. In this detail view controller I declare a few gestures that need to do certain things on their respective views only. Here is the code:
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(changeModeButtonPushed:)];
[tap setNumberOfTapsRequired:2];
[tap setNumberOfTouchesRequired:1];
[tap setDelegate:self];
[openGLView addGestureRecognizer:tap];
[tap release];
UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(touchDidDrag:)];
[panRecognizer setMaximumNumberOfTouches:1];
[openGLView addGestureRecognizer:panRecognizer];
[panRecognizer release];
UIPanGestureRecognizer *shiftRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(shiftView:)];
[shiftRecognizer setMinimumNumberOfTouches:2];
[openGLView addGestureRecognizer:shiftRecognizer];
[shiftRecognizer release];
UIPinchGestureRecognizer *pinchRecog = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(viewPinched:)];
[openGLView addGestureRecognizer:pinchRecog];
[pinchRecog release];
So I need to have two of these detail views load up next to each other inside of this parent view, and then I need to be able to do these gestures on one view or the other, and have that view respond.
The problem is that when I 1 finger pan around with 1 finger, sometimes it will call on the view it is supposed to, but most often, it fires on the other view! It doesn't make any sense! I have tried debugging and everything else I can think of, but I just can't see how two separately declared objects can get mixed up like this.
To make things stranger, there are some gestures that do work correctly. So it's only this one finger pan around gesture that screws everything up.
What could I be missing? How can I even debug this? Everything is looking like the objects are indeed separate, but they just aren't behaving that way...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以通过找出手势识别器正在调用的视图来调试/解决此问题:看看这段代码:
(void)NAMEOFFUNCTION:(UITapGestureRecognizer*)recognizer {
过滤所有子视图,在本例中我正在检查查看手指触摸是否低于定义的 x 坐标和 y 坐标。首先检查该点是否在 _buttonVIew 子视图内://
然后检查触摸是否在低于 50 的坐标
}
You could debug/solve this by finding out what view your gesture recogniser is calling on: Have a look at this code:
(void)NAMEOFFUNCTION:(UITapGestureRecognizer*)recognizer {
filter through all your subviews, in this example i'm checking to see if the finger touch is below a defined x and then y coordinate. First check to see if the point is inside the _buttonVIew subview://
Then check to see if the touch is in a coordinate lower than 50
}