• Windows Phone 8.1开发:触控和指针事件2


    原文出自:http://www.bcmeng.com/windows-phone-touch1/

    请在此输入内容(想死啊,写了一个小时,直接没保存不小心删掉了。那就简单说说吧)Pointer事件有以下事件:

    • PointerCanceled
    • PointerEntered
    • PointerExited
    • PointerMoved
    • PointerPressed
    • PointerReleased
    • PointerCaptureLost

    其引发顺序如下:

    当点击时:即Tap事件引发的触摸和指针事件顺序如下:

    12:4:8-PointerEntered事件发生

    12:4:8-PointerPressed事件发生
    12:4:8-ManipulationStarting事件发生
    12:4:8-PointerMoved事件发生
    12:4:8-PointerMoved事件发生
    12:4:8-PointerReleased事件发生
    12:4:8-Tapped事件发生
    12:4:8-PointerExited事件发生

    当长按时:即righttap事件引发的触摸和指针事件如下:
    12:6:15-PointerEntered事件发生
    12:6:15-PointerPressed事件发生
    12:6:15-ManipulationStarting事件发生
    12:6:15-PointerMoved事件发生
    12:6:15-PointerMoved事件发生
    12:6:16-PointerReleased事件发生
    12:6:16-RightTapped事件发生
    12:6:16-PointerExited事件发生

    关于各个指针事件的含义,大家根据名称也能意会,小梦刚才写的很详细,只不过没了,大家就直接参考MSDN文档吧。不过要注意:

    每当触控操作产生 PointerPressed 事件时,该事件紧接在 PointerEntered 事件之后,并且所有事件数据对于这两个事件具有相同的信息(相同的指针 ID、相同的位置等)

     PointerPressedPointerReleased事件并不总是成对出现的。您的应用程序应该倾听并处理可能得出一个指向下的动作(比如无论如何PointerExitedPointerCanceledPointerCaptureLost)。

    下面演示一个通过指针事件和LIne控件实现的笔触画图实例:

    首先定义一个画布:

    <Canvas Name=”canvas”
    Background=”Transparent”
    PointerPressed=”canvas_PointerPressed”
    PointerMoved=”canvas_PointerMoved”
    ></Canvas>

    后台逻辑:

    private Point currentPoint; //最新的,当前的点
    private Point oldPoint;//上一个点
    
    private void canvas_PointerPressed(object sender, PointerRoutedEventArgs e)
    {
    currentPoint = e.GetCurrentPoint(canvas).Position;
    oldPoint = currentPoint;
    }
    
    private void canvas_PointerMoved(object sender, PointerRoutedEventArgs e)
    {
    currentPoint = e.GetCurrentPoint(canvas).Position;
    
    Line line = new Line() { X1 = currentPoint.X, Y1 = currentPoint.Y, X2 = oldPoint.X, Y2 = oldPoint.Y };
    
    line.Stroke = new SolidColorBrush(Colors.Red);
    line.StrokeThickness = 5;
    line.StrokeLineJoin = PenLineJoin.Round;
    line.StrokeStartLineCap = PenLineCap.Round;
    line.StrokeEndLineCap = PenLineCap.Round;
    this.canvas.Children.Add(line);
    oldPoint = currentPoint;
    }

    如果对Line的属性不清楚,请参考MSDN:http://msdn.microsoft.com/library/windows/apps/system.windows.shapes.shape(v=vs.105).aspx

    运行效果如下:

    Windows Phone 8.1开发:触控和指针事件2 - 编程小梦 - 1Windows Phone 8.1开发:触控和指针事件2 - 编程小梦 - 2

    windows phone触控和指针源代码下载;点我下载哦!

  • 相关阅读:
    JavaScript的object和Array引用类型
    JavaScript中JSON的序列化与解析
    JavaScript获取url后面的参数
    JavaScript事件处理程序
    JavaScript手机端页面滑动到底部加载信息(移动端ajax分页)
    666
    jquery的键盘事件
    如何判断是不是微信登录浏览器
    写的挺好 placeholder 的模拟用法
    下雪了还是下冰雹了
  • 原文地址:https://www.cnblogs.com/xdoudou/p/3945235.html
Copyright © 2020-2023  润新知