我有两个视图控制器同时使用视图控制器遏制出现在屏幕上,实现与苹果的代码示例相同。调用它们视图控制器A(vcA)和视图控制器B(vcB)以及容器视图控制器(containerVC)。如何跟踪两个UIViewcontrollers之间的UITouches? (使用遏制)
每个vcA和vcB都有一个对象网格,我希望能够将对象从vcA拖到vcB。更具体地说,我想要在vcB中触发一次触发vcB中的touchesMoved:withEvent方法,一旦它位于边界vcB内。
我已经覆盖了touchesMoved:在containerVC withEvent方法,跟踪通过点击测试触摸,并试图转发触摸下 UIView的层次结构如下所示:
// in the containerVC
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
CGPoint locationPoint = [[touches anyObject] locationInView:self.view];
UIView* touchIsInViewControllerA = [vcA hitTest:locationPoint withEvent:event];
if (touchIsInViewControllerA) {
NSLog(@"Touch is in vcA");
return;
}
UIView* touchIsInViewControllerB = [vcB hitTest:locationPoint withEvent:event];
if (touchIsInViewControllerB) {
NSLog(@"Touch is in vcB");
[vcB touchesMoved:touches withEvent:event]; // this causes a crash
}
}
这似乎是递归,containerVC将触摸事件按下层次结构,然后vcB将触摸事件传递回层次结构。
我的问题:有没有办法让vcB将touch事件传回给containerVC的响应器链?或者我应该以一种不同的方式实现 - 使vcB成为vcA的代表,并让containerVC脱离等式?
注:我猜共同应对将放弃VC容纳图案,并保持它在同一个视图控制器,但是在这个例子中未显示的原因,我觉得让他们分开工作会更好我 - 除非它是完全疯狂和超级哈克这样做...