2014-04-11 7 views
1

CrossSliding 이벤트에 연결하여 GestureRecognizer으로 가로 스 와이프 제스처를 감지하려고합니다.GestureRecognizer 스 와이프 제스처

 _gr = new GestureRecognizer 
     { 
      GestureSettings = GestureSettings.ManipulationTranslateX | 
           GestureSettings.ManipulationTranslateY | 
           GestureSettings.CrossSlide 
     }; 

     _gr.CrossSliding += OnSwipe; 
     _gr.ManipulationStarted += OnManipulationStarted; 
     _gr.ManipulationUpdated += OnManipulationUpdated; 
     _gr.ManipulationCompleted += OnManipulationCompleted; 

     _gr.CrossSlideHorizontally = true; 

위의 코드에서 알 수 있듯이 스 와이프가 감지되고 제스처가 드래그됩니다.

내 문제는 스 와이프 제스처를 사용자 지정할 수없는 것입니다.

제스처가 스 와이프로 간주되기 전에 사용자가 포인터를 드래그해야하는 최소 속도와 거리를 사용자 정의하고 싶습니다. 현재 상태에서 가장 낮고 가장 작은 수평 끌기 동작으로도 CrossSliding 이벤트가 트리거됩니다.

제스처를 사용자 정의 할 수있는 CrossSlideThresholds 클래스를 보았지만 스 와이프 제스처의 속도와 거리를 구성하는 데 사용 방법을 알 수 없습니다.

CrossSliding 이벤트가 스 와이프를 감지하는 적절한 방법입니까? 그렇다면 어떻게 속도와 슬쩍 거리를 구성 할 수 있습니까?

그렇지 않다면 어떻게 스 와이프 제스처를 감지 할 수 있습니까?

+0

당신이 할 슬쩍을 이해합니까? Windows 8에서는 목록 항목을 선택하고 크로스 슬라이딩을 사용하면이 제스처가 'ScrollViewer'의 패닝 방향에 수직이라고 설명합니다. 그게 당신이 탐지하려고하는 것입니까? –

+0

아니, 그게 아니야, 당신이 책이나 앨범 커버의 페이지를 통해 장치 (희망이 합리적인)을 통해 영화를 쓸어 버릴 것처럼 빠른 수평 또는 수직 터치 포인트 움직임을 의미합니다. 나는 문서를 다시 읽고 슬쩍을 감지 할 수있는 방법이 없다는 결론에 도달했습니다. 내 자신의 검색을 구현하고 대답을 추가합니다 – thumbmunkeys

답변

0

스 와이프 감지 기능이 없기 때문에 자체 탐지 방법을 구현했습니다.

코드가 가로 스 와이프를 감지합니다.

표시 된 방법

GestureRecognizer 이벤트에 대한 이벤트 핸들러입니다

readonly Stopwatch _manipulationTimer = new Stopwatch(); 

public void OnManipulationStarted(ManipulationStartedEventArgs e) 
{ 
    _manipulationTimer.Restart(); 
} 

public void OnManipulationCompleted(ManipulationCompletedEventArgs e) 
{ 
    var millis = _manipulationTimer.ElapsedMilliseconds; 

    if (Math.Abs(e.Cumulative.Translation.Y) < MaxVerticalSwipeDistanceInPix && 
     Math.Abs(e.Cumulative.Translation.X) > MinHorizontalSwipeDistanceInPix && 
     millis > MinSwipeDurationInMillis && 
     millis < MaxSwipeDurationInMillis && 
     Math.Abs(e.Cumulative.Scale - 1) < 0.01 // 1 touch point 
     ) 
    { 
     var leftSwipe = e.Cumulative.Translation.X < 0; 
     if (leftSwipe) 
     { 
     } 
     else // right swipe 
     {    
     } 
    } 

    _manipulationTimer.Stop(); 
    _manipulationTimer.Reset(); 
} 
+1

그것을 할 수있는 좋은 방법 같아. 또한 'ManipulationInertiaStarting' 이벤트를 처리하고 변환 속도를 확인하여 제스처의 방향을 확인하면 제스처를 감지 할 수 있습니다. –

+0

@FilipSkakun 제안에 감사드립니다. 나는 그것에 대해 생각해 보지 않았습니다. – thumbmunkeys

관련 문제