关于多点触控的问题

时间:2011-04-12 19:31:24

标签: iphone cocoa-touch xcode

我有几个uiimages,我可以使用multitouches在iphonescreen上移动。问题是我希望将它们分成两个“团队”,一个“团队”的uiimages,我移动到我选择的区域内,一个“团队”,我可以在屏幕上移动。

我的问题是如何使用触摸方法(touchesbegan,touchesended,touchesmoved)两个uiimage“团队”和他们的cgpoints没有来自两个“团队”的cgpoints相互交叉并给出错误的uiimages错误的位置屏幕。第一个“团队”使用touchesbegan,touchesmoved和touchesended方法。第二个“团队”只使用了touchesended方法。

这是我的代码。我希望2个“团队”不要在触摸式方法中相互交叉

 -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
     //1st team
     for(UITouch *touch in touches){

     // Send to the dispatch method, which will make sure the appropriate subview is acted upon
     [self getRubyAtPoint:[touch locationInView:self.view]forEvent: nil]; 

     }
 }

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {

NSLog(@"touchesEnded");
//1st team
// Enumerates through all touch object
for (UITouch *touch in touches) {
    // Sends to the dispatch method, which will make sure the appropriate subview is acted upon
    [self dispatchTouchEndEvent:[touch view] toPosition:[touch locationInView:self.view]];
}

    //2nd team
UITouch *touch = [touches anyObject];
CGPoint currentTouch = [touch locationInView:self.view];    

[self getPieceAtPoint:currentTouch];

 }

 - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
     //1st team
 NSLog(@"touchesMoved");

 // Enumerates through all touch objects
 for (UITouch *touch in touches) {

     // Send to the dispatch method, which will make sure the appropriate subview is acted upon
     [self dispatchTouchEvent:[touch view] toPosition:[touch locationInView:self.view]];

 }
  }

1 个答案:

答案 0 :(得分:1)

如果我理解,你问的是如何让getPieceAtPoint等方法对错误的团队采取行动。

我想我只是为每个团队添加一个唯一的标记范围,并在采取行动之前检查它。

类似的东西:

UITouch *touch = [touches anyObject];
if ([touch view].tag>=TEAM_TWO_BASE_TAG)
{
     CGPoint currentTouch = [touch locationInView:self.view];    
     [self getPieceAtPoint:currentTouch];
}
相关问题