【问题标题】:how to make multi touch enabled ios app如何制作启用多点触控的 iOS 应用程序
【发布时间】:2012-05-31 12:34:10
【问题描述】:

我制作了一个应用程序,我想让它兼容多点触控。我试过环顾四周,但答案并不特定于我。 这是我的工作:

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) 我已经进入 Interface Builder 并选中了启用多点触控的复选框

3) 我构建并运行我的应用程序,它可以正常打开,当我去测试多点触控时,我按住“选项键”并单击并移动鼠标

4) (我试图让 computerPaddle 和 playerPaddle 都移动)但一次只能完成一项工作

我必须尝试修复它,但我不明白我哪里出错了。

任何帮助都是有用的。 谢了。

【问题讨论】:

    标签: iphone ios cocoa-touch multi-touch


    【解决方案1】:

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

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

    【讨论】:

    • 我认为您的想法是正确的,但 xlc0212 给出了编码。还是谢谢
    【解决方案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;
            }
        }
    }
    }
    

    【讨论】:

      猜你喜欢
      • 2010-09-27
      • 2023-04-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多