2011-04-12 50 views
1

我有几个使用多点触摸可以在iphonescreen上移动的uiimages。问题是我想要将它们分成两个“团队”,一个是我选择的区域内的一个“团队”,一个是我可以在整个屏幕上移动的“团队”。关于多点触摸的问题

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

这是我的代码。我希望2“团队”交叉彼此在touchesended方法

-(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

如果我理解鸵鸟政策,你问如何保持方法,如getPieceAtPoint作用于错了队。

我想我会为每个团队添加一个独特的标签范围,然后在对其采取行动之前对其进行检查。

喜欢的东西:

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

正是...我要上第一队的dispatchTouchEndEvent只有行为和getPieceAtPoint到2号球队在touchesended方法仅行为。一个标签?好吧,这听起来像个好主意。我会试试看,并让你知道。 thanx :) – iphonedevonthemake 2011-04-13 03:20:25

+0

它工作正常! thanx:D – iphonedevonthemake 2011-04-13 05:57:06