本文介绍了检测简单的触摸手势的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
任何人都可以就如何在WinRT的应用程序检测简单的触摸手势解释一下吗?我尝试使用 GestureRecognizer
类,但它没有工作:
公开的MainPage()
{
this.InitializeComponent();
Windows.UI.Input.GestureRecognizer克=新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; } 无效gr_Tapped(Windows.UI.Input.GestureRecognizer发件人,Windows.UI.Input.TappedEventArgs参数)
{
的Debug.WriteLine(gr_Tapped);
}
无效gr_RightTapped(Windows.UI.Input.GestureRecognizer发件人,Windows.UI.Input.RightTappedEventArgs参数)
{
的Debug.WriteLine(gr_RightTapped);
}
无效gr_Holding(Windows.UI.Input.GestureRecognizer发件人,Windows.UI.Input.HoldingEventArgs参数)
{
的Debug.WriteLine(gr_Holding);
}
无效gr_Dragging(Windows.UI.Input.GestureRecognizer发件人,Windows.UI.Input.DraggingEventArgs参数)
{
的Debug.WriteLine(gr_Dragging);
}
无效gr_CrossSliding(Windows.UI.Input.GestureRecognizer发件人,Windows.UI.Input.CrossSlidingEventArgs参数)
{
的Debug.WriteLine(gr_CrossSliding);
}
无效gr_ManipulationUpdated(Windows.UI.Input.GestureRecognizer发件人,Windows.UI.Input.ManipulationUpdatedEventArgs参数)
{
的Debug.WriteLine(gr_ManipulationUpdated);
}
无效gr_ManipulationStarted(Windows.UI.Input.GestureRecognizer发件人,Windows.UI.Input.ManipulationStartedEventArgs参数)
{
的Debug.WriteLine(gr_ManipulationStarted);
}
无效gr_ManipulationCompleted(Windows.UI.Input.GestureRecognizer发件人,Windows.UI.Input.ManipulationCompletedEventArgs参数)
{
的Debug.WriteLine(gr_ManipulationCompleted);
}
无效gr_ManipulationInertiaStarting(Windows.UI.Input.GestureRecognizer发件人,Windows.UI.Input.ManipulationInertiaStartingEventArgs参数)
{
的Debug.WriteLine(gr_ManipulationInertiaStarting);
}
解决方案
如果你会发现MainPage类有,你可以无需创建一个单独的 GestureRecognizer
。您可以通过设置 this.ManipulationMode
到 ManipulationModes.All
启用。这将让你看到的MainPages响应螺纹
, RightTapped
, ManipulationStarting
,在ManipulationStarted
,在ManipulationDelta code>和
在ManipulationCompleted
活动。
至于获得GestureRecongnizer根据本工作,此MSDN论坛发帖您将需要处理的MainPage的 PointerMoved
, PointerReleased
和指针pressed
事件,像这样。
Windows.UI.Input.GestureRecognizer克=新Windows.UI.Input.GestureRecognizer();公众的MainPage()
{
this.InitializeComponent();
this.Pointer pressed + = MainPage_Pointer pressed;
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;
}无效MainPage_PointerReleased(对象发件人,PointerRoutedEventArgs E)
{
VAR PS = e.GetIntermediatePoints(NULL);
如果(PS =空&放大器;!&放大器; ps.Count大于0)
{
gr.ProcessUpEvent(PS [0]);
e.Handled =真实的;
gr.CompleteGesture();
}
}无效MainPage_PointerMoved(对象发件人,PointerRoutedEventArgs E)
{
gr.ProcessMoveEvents(e.GetIntermediatePoints(NULL));
e.Handled =真实的;
}虚空MainPage_Pointer pressed(对象发件人,PointerRoutedEventArgs E)
{
VAR PS = e.GetIntermediatePoints(NULL);
如果(PS =空&放大器;!&放大器; ps.Count大于0)
{
gr.ProcessDownEvent(PS [0]);
e.Handled =真实的;
}
}
按照你需要启用CrossSlide事件将它添加到您的GestureRecongnizer搭好CrossSlideThresholds和方向。
从最后一个环节:
example:
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;
and make sure it is added to your 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;
这篇关于检测简单的触摸手势的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!