【问题标题】:a question about multitouch关于多点触控的问题
【发布时间】: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


    【解决方案1】:

    如果我理解,您是在问如何防止 getPieceAtPoint 等方法作用于错误的团队。

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

    类似:

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

    【讨论】:

    • 完全正确...我希望 dispatchTouchEndEvent 仅作用于第一个团队,而 getPieceAtPoint 仅作用于 touchesended 方法中的第二个团队。标签?好的..这听起来是个好主意。我会试试看,让你知道。谢谢 :)
    猜你喜欢
    • 1970-01-01
    • 2015-05-20
    • 1970-01-01
    • 1970-01-01
    • 2023-03-12
    • 1970-01-01
    • 2014-02-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多