【发布时间】:2011-04-12 19:31:23
【问题描述】:
我有几个 uiimages 可以使用多点触控在 iphonescreen 上移动。问题是我想将它们分成两个“团队”,一个是我在我选择的区域内移动的 uiimages 的“团队”,另一个是我可以在整个屏幕上移动的“团队”。
我的问题是如何为两个 uiimage“团队”及其 cgpoints 使用触摸方法(touchesbegan、touchesended、touchesmoved),而不会让两个“团队”的 cgpoints 相互交叉并在 uiimages 上给出错误的位置屏幕。第一个“团队”使用 touchesbegan、touchesmoved 和 touchesended 方法。第二个“团队”只使用 touchesended 方法。
这是我的代码。我希望这两个“团队”不要在 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]];
}
}
【问题讨论】:
标签: iphone cocoa-touch xcode