2012-05-31 21 views
0

我已经做了一个应用程序,我想让它多点触控兼容。我试过四处寻找,但答案并不是特定于我的。 这里是我做的:如何使多点触控启用iOS应用程序

1)我的编码:

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

[self touchesMoved:touches withEvent:event]; 
if (gameState == kGameStatePaused) {(gameState = kGameStateRunning);} 
} 

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { 
if(gameState == kGameStateRunning) { 

    UITouch *touch = [[event allTouches] anyObject]; 
    CGPoint location = [touch locationInView:touch.view]; 
    if(location.x > 400) { 

     CGPoint yLocation = CGPointMake(playerPaddle.center.x, location.y); 
     playerPaddle.center = yLocation; 
    } 

    if (gameStyle == kGameStyleTwoP) { 
     if(location.x < 100) { 

      CGPoint yLocation2 = CGPointMake(computerPaddle.center.x, location.y); 
      computerPaddle.center = yLocation2; 
     } 
    } 
} 

2)我已经到界面生成器和检查多点触控启用

3盒)我建立并运行我的应用程序并打开正确,当我去测试多点触控我按住“选项键”,然后点击并移动鼠标

4)(我正在试图让computerPaddle和playerPaddle都移动),但只有一个作品在时间

我必须尝试解决它,但我不明白我要去哪里错了。

任何帮助都很有用。 THX。

回答

2

看这条线

UITouch *touch = [[event allTouches] anyObject]; 

你只需要一点触而忽略休息,这就是为什么只有一两件事可以移动

用一个for循环,以便更换就可以解决问题

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { 
if(gameState == kGameStateRunning) { 

    for (UITouch *touch in [event allTouches]) { 
    CGPoint location = [touch locationInView:touch.view]; 
    if(location.x > 400) { 

     CGPoint yLocation = CGPointMake(playerPaddle.center.x, location.y); 
     playerPaddle.center = yLocation; 
    } 

    if (gameStyle == kGameStyleTwoP) { 
     if(location.x < 100) { 

      CGPoint yLocation2 = CGPointMake(computerPaddle.center.x, location.y); 
      computerPaddle.center = yLocation2; 
     } 
    } 
} 
} 
10

UIView上有一个名为multipleTouchEnabled的属性,您可以将其设置为YES以启用它(默认为NO)。

此外,您应该循环处理touchesMoved中收到的touches集合中的所有接触。

+0

我认为你有正确的想法,但xlc0212给了编码。无论如何 – burkel

相关问题