Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/121.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 如何制作支持多点触摸的ios应用程序_Iphone_Ios_Cocoa Touch_Multi Touch - Fatal编程技术网

Iphone 如何制作支持多点触摸的ios应用程序

Iphone 如何制作支持多点触摸的ios应用程序,iphone,ios,cocoa-touch,multi-touch,Iphone,Ios,Cocoa Touch,Multi Touch,我已经做了一个应用程序,我想让它多点触摸兼容。我试着四处看看,但答案并不针对我。 以下是我的工作: 1) 我的编码: - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { [self touchesMoved:touches withEvent:event]; if (gameState == kGameStatePaused) {(gameState = kGameStateRunning);} } - (vo

我已经做了一个应用程序,我想让它多点触摸兼容。我试着四处看看,但答案并不针对我。 以下是我的工作:

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;
        }
    }
}
-(void)touchesbeated:(NSSet*)toucheevent:(UIEvent*)event{
[自我触摸移动:触摸事件:事件];
如果(gameState==kGameStatePaused){(gameState=kGameStateRunning);}
}
-(无效)触摸移动:(NSSet*)触摸事件:(UIEvent*)事件{
如果(游戏状态==kGameStateRunning){
UITouch*touch=[[event AllTouchs]anyObject];
CGPoint location=[touch locationInView:touch.view];
如果(位置x>400){
CGPoint yLocation=CGPointMake(playerPaddle.center.x,location.y);
playerPaddle.center=y位置;
}
if(gameStyle==kGameStyleTwoP){
如果(位置x<100){
CGPoint yLocation2=CGPointMake(computerblade.center.x,location.y);
Computer Pable.center=yLocation2;
}
}
}
2) 我进入Interface Builder并选中了启用多点触控的复选框

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

4) (我试图让Computer Padle和playerPaddle同时移动)但一次只能移动其中一个

我得设法把它修好,但我不明白我哪里出了问题

任何帮助都是有用的。
THX.

UIView上有一个名为
MultipleToTouchEnabled
的属性,您可以将其设置为“是”以启用它(默认值为“否”)


此外,您应该循环处理在
touchesMoved

中收到的
touchesMoved
集合中的所有触摸。UIView上有一个名为
multipleTouchEnabled
的属性,您可以将其设置为是以启用它(默认为否)

此外,您应该循环处理在
touchsmoved
中收到的
touchs
集合中的所有触摸。请看这一行

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;
        }
    }
}
}
-(无效)触摸移动:(NSSet*)触摸事件:(UIEvent*)事件{
如果(游戏状态==kGameStateRunning){
用于(UITouch*触摸输入[事件所有触摸]){
CGPoint location=[touch locationInView:touch.view];
如果(位置x>400){
CGPoint yLocation=CGPointMake(playerPaddle.center.x,location.y);
playerPaddle.center=y位置;
}
if(gameStyle==kGameStyleTwoP){
如果(位置x<100){
CGPoint yLocation2=CGPointMake(computerblade.center.x,location.y);
Computer Pable.center=yLocation2;
}
}
}
}
看这行

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;
        }
    }
}
}
-(无效)触摸移动:(NSSet*)触摸事件:(UIEvent*)事件{
如果(游戏状态==kGameStateRunning){
用于(UITouch*触摸输入[事件所有触摸]){
CGPoint location=[touch locationInView:touch.view];
如果(位置x>400){
CGPoint yLocation=CGPointMake(playerPaddle.center.x,location.y);
playerPaddle.center=y位置;
}
if(gameStyle==kGameStyleTwoP){
如果(位置x<100){
CGPoint yLocation2=CGPointMake(computerblade.center.x,location.y);
Computer Pable.center=yLocation2;
}
}
}
}

我认为您的想法是正确的,但xlc0212给出了编码。无论如何,thx我认为您的想法是正确的,但xlc0212给出了编码。无论如何,thx