2014-11-27 1 views
0

현재 화면에서 두 손가락으로 탭하고 하나를 제거했지만 다른 손가락으로 계속 누르면 touchesEnded 메쏘드가 호출됩니다.전화를 건 경우에만 터치합니다.

그러나보기에 더 이상 닿지 않으면 메서드는 뭔가 수행하기를 원합니다.

장면에 아직 닿은 경우 touchesEnded- 방법 내에서 어떻게 확인할 수 있습니까?

답변

0

touchesBegan 및 메쏘드는 화면에서 발생하는 매 터치마다 매번 호출됩니다. 화면상의 각 터치는 UITouch 오브젝트와 연관됩니다. 이러한 메서드에 대한 매개 변수 인 (NSSet*) touches 개체의 이벤트와 관련된 모든 접촉을 찾을 수 있습니다.

전역 변수를 사용하여 원래 터치를 추적해야합니다.

@implementation GameScene 
{ 
    UITouch* currentTouch; //This variable will keep track of the touch. 
} 

이제, touchesBegan 방법에 : 당신의 gameScene의 구현에서

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 
    /* Called when a touch begins */ 

    for (UITouch *touch in touches) { 
     if (currentTouch == nil) { 
      currentTouch = touch; 

      //Handle touch code here, not outside. 

     } 
    } 
} 

그리고 touchesEnded 방법에

:

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    for (UITouch *touch in touches) { 

     if ([touch isEqual:currentTouch]) { 
      //This is the tracked touch, handle touch ending here. 

      currentTouch = nil; 
     } 
    } 
} 

위의 코드는 당신이 처리 할 수 ​​있도록해야한다 단일 터치 객체를 터치합니다.

더 나은 이해를 위해 Apple 터치 처리 가이드 here을 읽을 수 있습니다.

+1

'touchesBegan :'루프에서 'touchNum'변수를 터치하고 touchNum에 추가합니다. 'touchesEnded :'와'touchesCancelled :'는 터치를 반복하고 touchNum에서 뺍니다. – Okapi

관련 문제