2012-05-31 4 views
0

앱을 만들었으며 멀티 터치와 호환되도록하고 싶습니다. 나는 주변을 둘러 보았지만 대답은 나의 것과 관련이 없다.멀티 터치 사용 가능 iOS 앱을 만드는 방법

1) 내 코딩 : 내가 구축하고 내 응용 프로그램을 실행) 인터페이스 빌더에 사라와 멀티 터치가

3을 활성화하기위한 상자를 체크 한

- (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) 여기 내가하는 일입니다 올바르게 열리고 멀티 터치를 테스트 할 때 "옵션 키"를 누르고 마우스를 클릭하고 움직입니다.

4) (computerPaddle 및 playerPaddle을 둘 다 움직이려고 함)하지만 시간 :

나는 그것을 고치려고 노력해야한다. 그러나 내가 어디로 잘못 가고 있는지 이해할 수 없다.

도움이됩니다. THX.

답변

2

은 하나의 터치를 가지고 단 한 가지 문제

- (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입니다).

또한 으로 수신되는 touches 세트의 모든 터치를 처리하려면 루프해야합니다.

+0

을 수정해야하므로 루프에 대한 교체

를 이동할 수있는 이유 휴식과 그게 전부 무시

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

이 줄을 보면 나는 당신이 올바른 생각을 갖고 있었지만 xlc0212가 코딩을했다고 생각합니다. 어쨌든 – burkel