我有一个名为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];
所以我需要在这个父视图中将两个这样的细节视图相互加载,然后我需要能够在一个视图或另一个视图上执行这些操作,并让该视图响应。 / p>
问题是当我用一根手指摇动手指时,它有时会调用它应该的视图,但最常见的是,它会在另一个视图上触发!它没有任何意义!我已经尝试过调试以及我能想到的所有其他内容,但我只是看不出两个单独声明的对象如何混淆这样。
为了让事情变得陌生,有些姿势做正常工作。因此,只有这一个手指平移手势才能解决所有问题。
我能错过什么?我怎么能调试这个?一切都看起来像对象确实是分开的,但他们只是不那么表现......
答案 0 :(得分:0)
你可以通过找出你的手势识别器正在调用的视图来调试/解决这个问题:看看这段代码:
(void)NAMEOFFUNCTION:(UITapGestureRecognizer *)识别器{
if ([yourViewController.view pointInside:[recognizer locationInView:presentationSlideViewController.view] withEvent:nil]) {
}
过滤所有子视图,在此示例中,我要检查手指触摸是否低于定义的x然后是y坐标。首先检查点是否在_buttonVIew子视图内://
if ([_buttonView pointInside:[recognizer locationInView:_buttonView] withEvent:nil]) {
然后检查触摸是否在低于50的坐标
if (([recognizer locationInView:_buttonView].x < 50) && ([_leftArrow isEnabled])) {
pageIndex -= 1;
}
//otheriwse check to see if its over 970
else if (([recognizer locationInView:_buttonView].x > 970) && ([_rightArrow isEnabled])) {
pageIndex += 1;
}
[self scrollViewScrollToRect:pageIndex];
[self fadeArrows:1.0];
return;
}
}