重新想象 Windows 8 Store Apps (50) - 输入: 边缘手势, 手势操作, 手势识别
作者:webabcd
介绍
重新想象 Windows 8 Store Apps 之 手势
- 监测边缘手势
- 手势操作 - Manipulate 的应用(位移手势,缩放手势,旋转手势)
- 手势识别 - GestureRecognizer 的应用
示例
1、演示如何监测边缘手势
Input/Touch/EdgeGestureDemo.xaml
<Page
x:Class="XamlDemo.Input.Touch.EdgeGestureDemo"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:XamlDemo.Input.Touch"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"> <Grid Background="Transparent">
<StackPanel Margin="120 0 0 0"> <TextBlock Name="lblMsg" FontSize="14.667" /> </StackPanel>
</Grid>
</Page>
Input/Touch/EdgeGestureDemo.xaml.cs
/*
* 演示如何监测边缘手势
*
* EdgeGesture - 边缘手势的帮助类
* GetForCurrentView() - 获取当前的 EdgeGesture 对象
* Starting - 边缘手势开始时触发的事件
* Completed - 边缘手势完成后触发的事件
* Canceled - 边缘手势取消后触发的事件
*
* EdgeGestureEventArgs - 触发边缘手势事件后的事件参数
* EdgeGestureKind - 边缘手势的输入类型(Touch, Keyboard, Mouse)
*/ using System;
using Windows.UI.Input;
using Windows.UI.Xaml.Controls; namespace XamlDemo.Input.Touch
{
public sealed partial class EdgeGestureDemo : Page
{
public EdgeGestureDemo()
{
this.InitializeComponent(); EdgeGesture edgeGesture = EdgeGesture.GetForCurrentView(); edgeGesture.Canceled += edgeGesture_Canceled;
edgeGesture.Completed += edgeGesture_Completed;
edgeGesture.Starting += edgeGesture_Starting;
} void edgeGesture_Starting(EdgeGesture sender, EdgeGestureEventArgs args)
{
lblMsg.Text += "EdgeGesture Starting";
lblMsg.Text += Environment.NewLine;
} void edgeGesture_Completed(EdgeGesture sender, EdgeGestureEventArgs args)
{
lblMsg.Text += "EdgeGesture Completed";
lblMsg.Text += Environment.NewLine;
} void edgeGesture_Canceled(EdgeGesture sender, EdgeGestureEventArgs args)
{
lblMsg.Text += "EdgeGesture Canceled";
lblMsg.Text += Environment.NewLine;
}
}
}
2、演示 Manipulate 的应用(位移手势,缩放手势,旋转手势)
Input/Touch/Manipulate.xaml
<Page
x:Class="XamlDemo.Input.Touch.Manipulate"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:XamlDemo.Input.Touch"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"> <Grid Background="Transparent">
<Grid Margin="120 0 0 0"> <TextBlock Name="lblMsg" FontSize="14.667" /> <Rectangle Name="rectangle" Height="200" Width="200" Fill="Orange" /> </Grid>
</Grid>
</Page>
Input/Touch/Manipulate.xaml.cs
/*
* 演示 Manipulate 的应用(位移手势,缩放手势,旋转手势)
*
*
* 注:Manipulate 一般用于手势操作,GestureRecognizer 一般用于手势识别
*
*
* UIElement - UI 元素
* ManipulationModes - 需要监测的手势(Windows.UI.Xaml.Input.ManipulationModes 枚举)
* 包括:位移手势以及是否带有位移惯性以及是否带有位移轨道,缩放手势以及是否带有缩放惯性,旋转手势以及是否带有旋转惯性
* ManipulationStarting - 触控操作开始时触发的事件
* ManipulationStarted - 触控操作开始后触发的事件
* ManipulationInertiaStarting - 触控操作的惯性开始时触发的事件
* ManipulationCompleted - 触控操作结束后触发的事件
* ManipulationDelta - 触控值发生变化时触发的事件
*
*
* ManipulationStartingRoutedEventArgs
* Container - 此 Manipulation 的容器
* Mode - 获取或设置 ManipulationModes
* Pivot - 获取或设置轴对象,ManipulationPivot 类型的数据
* Center - 旋转中心点
* Radius - 有效的旋转半径
*
* ManipulationStartedRoutedEventArgs
* Container - 此 Manipulation 的容器
* Cumulative - 自操作开始后的累计变化量,返回 ManipulationDelta 类型的对象
* Position - 触摸点相对于 UIElement 的位置
* Complete() - 马上完成 Manipulation 而不发生惯性
*
* ManipulationDeltaRoutedEventArgs
* Container - 此 Manipulation 的容器
* Cumulative - 自操作开始后的累计变化量,返回 ManipulationDelta 类型的对象
* Delta - 当前变化量,返回 ManipulationDelta 类型的对象
* Velocities - 当前变化的速率,返回 ManipulationVelocities 类型的对象
* IsInertial - 是否在惯性运动之中
* Position - 触摸点相对于 UIElement 的位置
* Complete() - 马上完成 Manipulation 而不发生惯性
*
* ManipulationInertiaStartingRoutedEventArgs
* Container - 此 Manipulation 的容器
* Cumulative - 自操作开始后的累计变化量,返回 ManipulationDelta 类型的对象
* Delta - 当前变化量,返回 ManipulationDelta 类型的对象
* Velocities - 当前变化的速率,返回 ManipulationVelocities 类型的对象
* ExpansionBehavior - 惯性的缩放行为,获取或设置 InertiaExpansionBehavior 类型的对象
* DesiredDeceleration - 惯性运动时,缩放的减慢速率
* DesiredExpansion - 惯性结束后,缩放的值
* RotationBehavior - 惯性的旋转行为,获取或设置 InertiaRotationBehavior 类型的对象
* DesiredDeceleration - 惯性运动时,旋转的减慢速率
* DesiredRotation - 惯性结束后,旋转的度数
* TranslationBehavior - 惯性的位移行为,获取或设置 InertiaTranslationBehavior 类型的对象
* DesiredDeceleration - 惯性运动时,直线位移的减慢速率
* DesiredDisplacement - 惯性结束后,直线位移的的值
*
* ManipulationCompletedRoutedEventArgs
* Container - 此 Manipulation 的容器
* Cumulative - 自操作开始后的累计变化量,返回 ManipulationDelta 类型的对象
* Velocities - 当前变化的速率,返回 ManipulationVelocities 类型的对象
* IsInertial - 结束前是否发生了惯性运动
* Position - 触摸点相对于 UIElement 的位置
*
*
* ManipulationDelta - 变化量
* Expansion - 触摸点间距离的变化,单位 dip
* Scale - 触摸点间距离的变化,以一个百分比表示
* Rotation - 旋转角度的变化,以角度为单位
* Translation - 位移的变化,Point 类型的对象
*
* ManipulationVelocities - 变化速率
* Angular - 旋转速度,单位:度/毫秒
* Expansion - 缩放速度,单位:dip/毫秒
* Linear - 直线位移速度,单位:Point/毫秒
*
*
* 什么是 dip: device independent pixels(设备独立像素),不管屏大小和分辨率,把屏幕分成 480 * 320 个点,其中每一点代表 1 dip
*/ using System;
using Windows.Foundation;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media; namespace XamlDemo.Input.Touch
{
public sealed partial class Manipulate : Page
{
private TransformGroup _transformGroup;
private CompositeTransform _compositeTransform;
private MatrixTransform _previousTransform; public Manipulate()
{
this.InitializeComponent(); // 监测全部手势
rectangle.ManipulationMode = ManipulationModes.All; _transformGroup = new TransformGroup();
_compositeTransform = new CompositeTransform();
_previousTransform = new MatrixTransform() { Matrix = Matrix.Identity }; _transformGroup.Children.Add(_previousTransform);
_transformGroup.Children.Add(_compositeTransform); rectangle.RenderTransform = _transformGroup; rectangle.ManipulationStarting += rectangle_ManipulationStarting;
rectangle.ManipulationStarted += rectangle_ManipulationStarted;
rectangle.ManipulationInertiaStarting += rectangle_ManipulationInertiaStarting;
rectangle.ManipulationCompleted += rectangle_ManipulationCompleted;
rectangle.ManipulationDelta += rectangle_ManipulationDelta;
} // 将触控操作的结果显示出来
void rectangle_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
{
_previousTransform.Matrix = _transformGroup.Value; // 获取操作点相对于此 GeneralTransform 的位置
Point center = _previousTransform.TransformPoint(new Point(e.Position.X, e.Position.Y));
_compositeTransform.CenterX = center.X;
_compositeTransform.CenterY = center.Y; _compositeTransform.Rotation = e.Delta.Rotation;
_compositeTransform.ScaleX = e.Delta.Scale;
_compositeTransform.ScaleY = e.Delta.Scale;
_compositeTransform.TranslateX = e.Delta.Translation.X;
_compositeTransform.TranslateY = e.Delta.Translation.Y;
} void rectangle_ManipulationStarting(object sender, ManipulationStartingRoutedEventArgs e)
{
lblMsg.Text += "ManipulationStarting";
lblMsg.Text += Environment.NewLine;
} void rectangle_ManipulationStarted(object sender, ManipulationStartedRoutedEventArgs e)
{
lblMsg.Text += "ManipulationStarted";
lblMsg.Text += Environment.NewLine;
} void rectangle_ManipulationInertiaStarting(object sender, ManipulationInertiaStartingRoutedEventArgs e)
{
lblMsg.Text += "ManipulationInertiaStarting";
lblMsg.Text += Environment.NewLine;
} void rectangle_ManipulationCompleted(object sender, ManipulationCompletedRoutedEventArgs e)
{
lblMsg.Text += "ManipulationCompleted";
lblMsg.Text += Environment.NewLine;
}
}
}
3、演示 GestureRecognizer 的应用
Input/Touch/GestureRecognizerDemo.xaml
<Page
x:Class="XamlDemo.Input.Touch.GestureRecognizerDemo"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:XamlDemo.Input.Touch"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"> <Grid Background="Transparent">
<StackPanel Margin="120 0 0 0"> <StackPanel Orientation="Horizontal">
<RadioButton Name="radVertical" GroupName="group" Content="垂直 Cross Slide" Click="radVertical_Click_1" IsChecked="True" />
<RadioButton Name="radHorizontal" GroupName="group" Content="水平 Cross Slide" Click="radHorizontal_Click_1" Margin="10 0 0 0" />
</StackPanel> <TextBlock Name="lblMsg" FontSize="14.667" Margin="0 10 0 0">
<Run>通过 GestureRecognizer 监测手势(本例以 Cross Slide 手势为例)</Run>
</TextBlock> </StackPanel>
</Grid>
</Page>
Input/Touch/GestureRecognizerDemo.xaml.cs
/*
* 演示 GestureRecognizer 的应用
*
* 本例以监测 Cross Slide 手势为例,其它类似
*
* 注:Manipulate 一般用于手势操作,GestureRecognizer 一般用于手势识别
*/ using System;
using Windows.UI.Input;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Input; namespace XamlDemo.Input.Touch
{
public sealed partial class GestureRecognizerDemo : Page
{
private GestureRecognizer _gestureRecognizer; public GestureRecognizerDemo()
{
this.InitializeComponent(); _gestureRecognizer = new GestureRecognizer(); /*
* Windows.UI.Input.GestureSettings 是一个 flag 枚举,其值包括:
* None, Tap, DoubleTap, Hold, HoldWithMouse, RightTap, Drag, CrossSlide, ManipulationTranslateX, ManipulationTranslateY, ManipulationTranslateRailsX, ManipulationTranslateRailsY, ManipulationRotate, ManipulationScale, ManipulationTranslateInertia, ManipulationRotateInertia, ManipulationScaleInertia
*/ // 监测 CrossSlide 手势
_gestureRecognizer.GestureSettings = GestureSettings.CrossSlide;
_gestureRecognizer.CrossSliding += _gestureRecognizer_CrossSliding; this.PointerMoved += GestureRecognizerDemo_PointerMoved;
this.PointerPressed += GestureRecognizerDemo_PointerPressed;
this.PointerReleased += GestureRecognizerDemo_PointerReleased;
} void GestureRecognizerDemo_PointerPressed(object sender, PointerRoutedEventArgs e)
{
// 告诉 GestureRecognizer 指针按下了,以便 GestureRecognizer 做手势监测
_gestureRecognizer.ProcessDownEvent(e.GetCurrentPoint(null));
} void GestureRecognizerDemo_PointerMoved(object sender, PointerRoutedEventArgs e)
{
// 告诉 GestureRecognizer 指针移动中,以便 GestureRecognizer 做手势监测
_gestureRecognizer.ProcessMoveEvents(e.GetIntermediatePoints(null));
} void GestureRecognizerDemo_PointerReleased(object sender, PointerRoutedEventArgs e)
{
// 告诉 GestureRecognizer 指针释放了,以便 GestureRecognizer 做手势监测
_gestureRecognizer.ProcessUpEvent(e.GetCurrentPoint(null));
} void _gestureRecognizer_CrossSliding(GestureRecognizer sender, CrossSlidingEventArgs args)
{
lblMsg.Text += Environment.NewLine;
lblMsg.Text += " CrossSliding: " + args.CrossSlidingState + "; " + args.Position.ToString();
} private void radVertical_Click_1(object sender, Windows.UI.Xaml.RoutedEventArgs e)
{
// 监测垂直 Cross Slide 手势
_gestureRecognizer.CrossSlideHorizontally = false;
} private void radHorizontal_Click_1(object sender, Windows.UI.Xaml.RoutedEventArgs e)
{
// 监测水平 Cross Slide 手势
_gestureRecognizer.CrossSlideHorizontally = true;
}
}
}
OK
[源码下载]
重新想象 Windows 8 Store Apps (50) - 输入: 边缘手势, 手势操作, 手势识别的更多相关文章
- 重新想象 Windows 8 Store Apps (51) - 输入: 涂鸦板
[源码下载] 重新想象 Windows 8 Store Apps (51) - 输入: 涂鸦板 作者:webabcd 介绍重新想象 Windows 8 Store Apps 之 涂鸦板 通过 Poin ...
- 重新想象 Windows 8 Store Apps (49) - 输入: 获取输入设备信息, 虚拟键盘, Tab 导航, Pointer, Tap, Drag, Drop
[源码下载] 重新想象 Windows 8 Store Apps (49) - 输入: 获取输入设备信息, 虚拟键盘, Tab 导航, Pointer, Tap, Drag, Drop 作者:weba ...
- 重新想象 Windows 8 Store Apps 系列文章索引
[源码下载][重新想象 Windows 8.1 Store Apps 系列文章] 重新想象 Windows 8 Store Apps 系列文章索引 作者:webabcd 1.重新想象 Windows ...
- 重新想象 Windows 8 Store Apps (16) - 控件基础: 依赖属性, 附加属性, 控件的继承关系, 路由事件和命中测试
原文:重新想象 Windows 8 Store Apps (16) - 控件基础: 依赖属性, 附加属性, 控件的继承关系, 路由事件和命中测试 [源码下载] 重新想象 Windows 8 Store ...
- 重新想象 Windows 8 Store Apps (38) - 契约: Search Contract
[源码下载] 重新想象 Windows 8 Store Apps (38) - 契约: Search Contract 作者:webabcd 介绍重新想象 Windows 8 Store Apps 之 ...
- 重新想象 Windows 8 Store Apps (39) - 契约: Share Contract
[源码下载] 重新想象 Windows 8 Store Apps (39) - 契约: Share Contract 作者:webabcd 介绍重新想象 Windows 8 Store Apps 之 ...
- 重新想象 Windows 8 Store Apps (52) - 绑定: 与 Element Model Indexer Style RelativeSource 绑定, 以及绑定中的数据转换
[源码下载] 重新想象 Windows 8 Store Apps (52) - 绑定: 与 Element Model Indexer Style RelativeSource 绑定, 以及绑定中的数 ...
- 重新想象 Windows 8 Store Apps (53) - 绑定: 与 ObservableCollection CollectionViewSource VirtualizedFilesVector VirtualizedItemsVector 绑定
[源码下载] 重新想象 Windows 8 Store Apps (53) - 绑定: 与 ObservableCollection CollectionViewSource VirtualizedF ...
- 重新想象 Windows 8 Store Apps (56) - 系统 UI: Scale, Snap, Orientation, High Contrast 等
[源码下载] 重新想象 Windows 8 Store Apps (56) - 系统 UI: Scale, Snap, Orientation, High Contrast 等 作者:webabcd ...
随机推荐
- tldr 的安卓客户端
上次在 Cheat (tldr, bropages) - Unix命令用法备忘单 这篇博文中提到过 tldr ,它跟 cheatsheet 的功能一样:用来查询一些常用命令的惯用法,呈现形式是简明扼要 ...
- PLSQL登录弹出空白框如何解决
转自:http://jingyan.baidu.com/article/066074d6760959c3c21cb0d6.html 出现登录弹出空白框这是由于win7的安全性提高了,在PLSQL ...
- Android复制assets目录下的图片到内存
转自:http://www.chenwg.com/android/android%E5%A4%8D%E5%88%B6assets%E7%9B%AE%E5%BD%95%E4%B8%8B%E7%9A%84 ...
- saiku、mondrian前奏之——立方体、维度、Schema的基本概念
以前介绍了几个基本工具:saiku 和 Schema Workbench,算是入门级别的了解多维报表,如果要继续深入,需要深入了解如下几个概念: 1.OLAP 联机分析处理,和他对应的是OLTP(联机 ...
- c++ 状态模式(state)
/************************************************************************/ /* 状态模式 */ /************* ...
- Java实现动态代理的两种方式
http://m.blog.csdn.net/article/details?id=49738887
- 公钥、私钥、CA认证、数字签名、U盾
感谢传智播客的方立勋老师,在一个教学视频上,他巧妙地以蒋介石给宋美龄写密信作为例子,生动地讲述了软件密码学知识. 加密分为对称加密和非对称加密,我们传统理解的,发送数据之前使用一个加密器加密,接到数据 ...
- 对Joint Training of Cascaded CNN for Face Detection一文的几点疑惑
最近读了Joint Training of Cascaded CNN for Face Detection这篇论文,论文中把之前人脸检测使用到的cascade cnn,从分开训练的模式,改为了联合训练 ...
- SecureCRT使用
SecureCRT可以说是linux远程终端的代名词,关于它的一些技巧必须掌握,,, 1.解决中文乱码 登陆主机,运行locale命令,确定语言选项LANG是否为 zh_CN.gb2312 或者 en ...
- 享元模式及C++实现
享元模式(flyweight) flyweight是轻量级的意思,中文这边翻译成享元,更容易让人理解一些. 享元模式是为了应对大量细粒度对象重复的问题.程序中存在大量细粒度的对象,每次要使用时都必须创 ...