2012-09-04 3 views
21

누구나 WinRT 앱에서 간단한 터치 동작을 감지하는 방법에 대해 설명 할 수 있습니까? 나는 GestureRecognizer 클래스를 사용하여 시도했지만 작동하지 않았다 :간단한 터치 동작 감지

public MainPage() 
    { 
     this.InitializeComponent(); 
     Windows.UI.Input.GestureRecognizer gr = new Windows.UI.Input.GestureRecognizer(); 
     gr.CrossSliding += gr_CrossSliding; 
     gr.Dragging += gr_Dragging; 
     gr.Holding += gr_Holding; 
     gr.ManipulationCompleted += gr_ManipulationCompleted; 
     gr.ManipulationInertiaStarting += gr_ManipulationInertiaStarting; 
     gr.ManipulationStarted += gr_ManipulationStarted; 
     gr.ManipulationUpdated += gr_ManipulationUpdated; 
     gr.RightTapped += gr_RightTapped; 
     gr.Tapped += gr_Tapped; 
     gr.GestureSettings = Windows.UI.Input.GestureSettings.ManipulationRotate | Windows.UI.Input.GestureSettings.ManipulationTranslateX | Windows.UI.Input.GestureSettings.ManipulationTranslateY | 
     Windows.UI.Input.GestureSettings.ManipulationScale | Windows.UI.Input.GestureSettings.ManipulationRotateInertia | Windows.UI.Input.GestureSettings.ManipulationScaleInertia | 
     Windows.UI.Input.GestureSettings.ManipulationTranslateInertia | Windows.UI.Input.GestureSettings.Tap; 

    } 

    void gr_Tapped(Windows.UI.Input.GestureRecognizer sender, Windows.UI.Input.TappedEventArgs args) 
    { 
     Debug.WriteLine("gr_Tapped"); 
    } 
    void gr_RightTapped(Windows.UI.Input.GestureRecognizer sender, Windows.UI.Input.RightTappedEventArgs args) 
    { 
     Debug.WriteLine("gr_RightTapped"); 
    } 
    void gr_Holding(Windows.UI.Input.GestureRecognizer sender, Windows.UI.Input.HoldingEventArgs args) 
    { 
     Debug.WriteLine("gr_Holding"); 
    } 
    void gr_Dragging(Windows.UI.Input.GestureRecognizer sender, Windows.UI.Input.DraggingEventArgs args) 
    { 
     Debug.WriteLine("gr_Dragging"); 
    } 
    void gr_CrossSliding(Windows.UI.Input.GestureRecognizer sender, Windows.UI.Input.CrossSlidingEventArgs args) 
    { 
     Debug.WriteLine("gr_CrossSliding"); 
    } 
    void gr_ManipulationUpdated(Windows.UI.Input.GestureRecognizer sender, Windows.UI.Input.ManipulationUpdatedEventArgs args) 
    { 
     Debug.WriteLine("gr_ManipulationUpdated"); 
    } 
    void gr_ManipulationStarted(Windows.UI.Input.GestureRecognizer sender, Windows.UI.Input.ManipulationStartedEventArgs args) 
    { 
     Debug.WriteLine("gr_ManipulationStarted"); 
    } 
    void gr_ManipulationCompleted(Windows.UI.Input.GestureRecognizer sender, Windows.UI.Input.ManipulationCompletedEventArgs args) 
    { 
     Debug.WriteLine("gr_ManipulationCompleted"); 
    } 
    void gr_ManipulationInertiaStarting(Windows.UI.Input.GestureRecognizer sender, Windows.UI.Input.ManipulationInertiaStartingEventArgs args) 
    { 
     Debug.WriteLine("gr_ManipulationInertiaStarting"); 
    } 
+0

에 추가됩니다. – test

답변

37

당신이 MainPage 클래스를 사용하면 별도의 GestureRecognizer을 만들지 않고 사용할 수 있습니다 자신의 조작 이벤트가 통지됩니다. this.ManipulationModeManipulationModes.All으로 설정하여 사용하도록 설정할 수 있습니다. 그러면 MainPages Tapped, RightTapped, ManipulationStarting, ManipulationStarted, ManipulationDeltaManipulationCompleted 이벤트에 대한 응답을 볼 수 있습니다.

지금까지이 Blog 당신이 그렇게 같은 MainPage의 PointerMoved, PointerReleasedPointerPressed 이벤트를 처리해야합니다이 MSDN Forum Posting에 따라 작동하도록 GestureRecongnizer을 받고있다. 당신이 당신의 GestureRecongnizer에 추가하고 CrossSlideThresholds 및 방향을 설정하여 CrossSlide 이벤트를 활성화하는 데 필요한 Documentation에 따르면


Windows.UI.Input.GestureRecognizer gr = new Windows.UI.Input.GestureRecognizer(); 

public MainPage() 
{ 
    this.InitializeComponent(); 
    this.PointerPressed += MainPage_PointerPressed; 
    this.PointerMoved += MainPage_PointerMoved; 
    this.PointerReleased += MainPage_PointerReleased; 
    gr.CrossSliding += gr_CrossSliding;  
    gr.Dragging += gr_Dragging;  
    gr.Holding += gr_Holding;  
    gr.ManipulationCompleted += gr_ManipulationCompleted;  
    gr.ManipulationInertiaStarting += gr_ManipulationInertiaStarting;  
    gr.ManipulationStarted += gr_ManipulationStarted;  
    gr.ManipulationUpdated += gr_ManipulationUpdated;  
    gr.RightTapped += gr_RightTapped;  
    gr.Tapped += gr_Tapped;  
    gr.GestureSettings = Windows.UI.Input.GestureSettings.ManipulationRotate | Windows.UI.Input.GestureSettings.ManipulationTranslateX | Windows.UI.Input.GestureSettings.ManipulationTranslateY |  
    Windows.UI.Input.GestureSettings.ManipulationScale | Windows.UI.Input.GestureSettings.ManipulationRotateInertia | Windows.UI.Input.GestureSettings.ManipulationScaleInertia |  
    Windows.UI.Input.GestureSettings.ManipulationTranslateInertia | Windows.UI.Input.GestureSettings.Tap; 
} 

void MainPage_PointerReleased(object sender, PointerRoutedEventArgs e) 
{ 
    var ps = e.GetIntermediatePoints(null); 
    if (ps != null && ps.Count > 0) 
    { 
     gr.ProcessUpEvent(ps[0]); 
     e.Handled = true; 
     gr.CompleteGesture(); 
    } 
} 

void MainPage_PointerMoved(object sender, PointerRoutedEventArgs e) 
{ 
    gr.ProcessMoveEvents(e.GetIntermediatePoints(null)); 
    e.Handled = true; 
} 

void MainPage_PointerPressed(object sender, PointerRoutedEventArgs e) 
{ 
    var ps = e.GetIntermediatePoints(null); 
    if (ps != null && ps.Count > 0) 
    { 
     gr.ProcessDownEvent(ps[0]); 
     e.Handled = true; 
    } 
} 
. 마지막 링크에서 :

CrossSlide를 지원하려면 CrossSlide를 GestureSettings 속성에 설정해야합니다. CrossSliding 거리 임계 값은 기본적으로 사용하지 않도록 설정되어 있습니다. CrossSlideThresholds를 사용하여이 값을 설정하십시오.

예 :

Windows.UI.Input.CrossSlideThresholds cst = new Windows.UI.Input.CrossSlideThresholds(); 
cst.SelectionStart = 2; 
cst.SpeedBumpStart = 3; 
cst.SpeedBumpEnd = 4; 
cst.RearrangeStart = 5; 
gr.CrossSlideHorizontally = true; 
gr.CrossSlideThresholds = cst; 
gr.CrossSliding += gr_CrossSliding; 

하고 있는지 확인하십시오 당신이 도청 이벤트 핸들러를 추가 한 곳에 내가 볼 수없는 당신의 GestureSettings

gr.GestureSettings = Windows.UI.Input.GestureSettings.ManipulationRotate | Windows.UI.Input.GestureSettings.ManipulationTranslateX | 
        Windows.UI.Input.GestureSettings.ManipulationScale | Windows.UI.Input.GestureSettings.ManipulationRotateInertia | 
        Windows.UI.Input.GestureSettings.ManipulationScaleInertia | Windows.UI.Input.GestureSettings.ManipulationTranslateInertia | 
        Windows.UI.Input.GestureSettings.Tap | Windows.UI.Input.GestureSettings.CrossSlide;