2011-08-15 2 views
0

...제스처 검출 IOS 3.1.3 IOS 3.1 및 I가있는 UIView에서 제스처를 감지하는 방법을 상술

> = 3.2.3 I이 코드를 사용하여 (예를 들어) : 레이아웃이 아닌 경우 누군가가 아이디어/예를

UISwipeGestureRecognizer *oneFingerSwipeLeft = 
    [[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(oneFingerSwipeLeft:)] autorelease]; 
    [oneFingerSwipeLeft setDirection:UISwipeGestureRecognizerDirectionLeft]; 
    [[self view] addGestureRecognizer:oneFingerSwipeLeft]; 

    UISwipeGestureRecognizer *oneFingerSwipeRight = 
    [[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(oneFingerSwipeRight:)] autorelease]; 
    [oneFingerSwipeRight setDirection:UISwipeGestureRecognizerDirectionRight]; 
    [[self view] addGestureRecognizer:oneFingerSwipeRight]; 

...

감사

답변

2

당신은 UIView를 서브 클래스 (또는 뷰 컨트롤러 내에서 물건을 구현해야 할거야 너무 복잡한) 이 아래로 손가락 진행에 대한 모든 손가락이 반드시지나 가게되어 가정하기 때문에 불완전한 솔루션입니다

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    if(!trackingTouch && [touches count] == 1) 
    { 
     trackingTouch = [touches anyObject]; 
     startingPoint = [trackingTouch locationInView:relevantView]; 
    } 
} 

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    if(trackingTouch && [touches containsObject:trackingTouch]) 
    { 
     CGPoint endingPoint = [trackingTouch locationInView:relevantView]; 
     trackingTouch = nil; 

     if(endingPoint.x < startingPoint.x) 
      NSLog(@"swipe left"); 
     else 
      NSLog(@"swipe right"); 
    } 
} 

- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    [self touchesEnded:touches withEvent:event]; 
} 

// don't really care about touchesMoved:withEvent: 

: 당신은 올드 UIResponder 방법 touchesBegan:withEvent: 너희 사용하여 직접 원하는 제스처, 예를 들어 등

을 추적 할 수 있습니다. touchesMoved:withEvent:에 일종의 최대 지속 시간 또는 트랙 속도를 구현하거나 터치가 최소 거리 이상 움직 였는지 확인하는 것이 좋습니다. 사람들이 애플이 UIGestureRecognizer을 제공하는 모든 종류의 것들에 대해 서로 다른 결정을 내리고 있었기 때문이라고 생각한다.

+0

고마워요 토미! – Maxime

관련 문제