windows8 开发教程 教你制作 多点触控Helper可将任意容器内任意对象进行多点缩放
http://blog.csdn.net/wangrenzhu2011/article/details/7732907 (转)
实现方法:
对Manipulation进行抽象化 使不同容器可共用多点缩放事件,
C# 代码如下:
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Windows.Foundation;
- using Windows.UI.Xaml;
- using Windows.UI.Xaml.Controls;
- using Windows.UI.Xaml.Input;
- using Windows.UI.Xaml.Media;
- using Windows.UI.Xaml.Media.Animation;
- namespace MetroTimeline
- {
- public class MetroManipulationHelper
- {
- /// <summary>
- /// 发生碰撞时的操作方法库
- /// </summary>
- public static Dictionary<Predicate<string>, Action<ManipulationDeltaRoutedEventArgs>>
- BoundaryFeedbackDict = new Dictionary<Predicate<string>, Action<ManipulationDeltaRoutedEventArgs>>();
- /// <summary>
- /// 多点触控开始后方法库
- /// </summary>
- public static Dictionary<Predicate<string>, Action<ManipulationStartedRoutedEventArgs>>
- ManipulationStartedDict = new Dictionary<Predicate<string>, Action<ManipulationStartedRoutedEventArgs>>();
- /// <summary>
- /// 多点触控完成后方法库
- /// </summary>
- public static Dictionary<Predicate<string>, Action<ManipulationCompletedRoutedEventArgs>>
- ManipulationCompletedDict = new Dictionary<Predicate<string>, Action<ManipulationCompletedRoutedEventArgs>>();
- /// <summary>
- /// 需要执行的方法的关键字
- /// </summary>
- private static string methodTag;
- public static string MethodTag
- {
- get { return MetroManipulationHelper.methodTag; }
- set { MetroManipulationHelper.methodTag = value; }
- }
- /// <summary>
- /// 将容器变为多点操控容器
- /// </summary>
- /// <param name="container"></param>
- /// <param name="mode"></param>
- /// <param name="trans"></param>
- /// <param name="scale"></param>
- /// <param name="rotation"></param>
- /// <param name="containerRect">容器相对父级菜单位置</param>
- public static void InitManipulation(FrameworkElement container, ManipulationModes mode,
- double trans, double scale, double rotation, Rect containerRect)
- {
- BoundaryFeedbackDict.Add(s => s.Equals("default"), e =>
- {
- var element = e.OriginalSource as FrameworkElement;
- var con = e.Container as Panel;
- var elementBounds = element.RenderTransform.TransformBounds(new Rect(e.Position, element.RenderSize));
- Point fp = new Point((elementBounds.Left + elementBounds.Right) / 2, (elementBounds.Top + elementBounds.Bottom) / 2);
- if (fp.X < containerRect.Left ||
- fp.X > containerRect.Right ||
- fp.Y < containerRect.Top ||
- fp.Y > containerRect.Bottom)
- {
- e.Complete();
- }
- });
- container.ManipulationStarting += ElementManipulationEventHandler(container, mode);
- container.ManipulationDelta += ElementManipulationDeltaEventHandler();
- container.ManipulationStarted += ElementManipulationStartedEventHandler();
- container.ManipulationCompleted += ElementManipulationCompletedEventHandler();
- container.ManipulationInertiaStarting += ElementManipulationInertiaStartingEventHandler(trans, scale, rotation);
- foreach (var item in (container as Panel).Children)
- {
- if (item.ManipulationMode == ManipulationModes.All)
- {
- var group = new TransformGroup();
- group.Children.Add(new TranslateTransform());
- group.Children.Add(new ScaleTransform());
- group.Children.Add(new RotateTransform());
- item.RenderTransform = group;
- }
- }
- }
- #region 多点手势方法
- #region 多点触控手势开始操作
- public static ManipulationStartingEventHandler ElementManipulationEventHandler(FrameworkElement element, ManipulationModes mode)
- {
- return (sender, e) =>
- {
- e.Container = element;
- e.Mode = mode;
- };
- }
- #endregion
- #region 多点触控手势过程中操作
- public static ManipulationDeltaEventHandler ElementManipulationDeltaEventHandler()
- {
- return ((sender, e) =>
- {
- var element = e.OriginalSource as FrameworkElement;
- var center = new Point(element.ActualWidth / 2, element.ActualHeight / 2);
- var tt = (element.RenderTransform as TransformGroup).Children[0] as TranslateTransform;
- tt.X += e.Delta.Translation.X;
- tt.Y += e.Delta.Translation.Y;
- var st = (element.RenderTransform as TransformGroup).Children[1] as ScaleTransform;
- st.CenterX = center.X;
- st.CenterY = center.Y;
- st.ScaleX *= e.Delta.Scale;
- st.ScaleY *= e.Delta.Scale;
- var rt = (element.RenderTransform as TransformGroup).Children[2] as RotateTransform;
- rt.CenterX = center.X;
- rt.CenterY = center.Y;
- rt.Angle += e.Delta.Rotation;
- if (e.IsInertial)
- if (null != BoundaryFeedbackDict)
- foreach (var item in BoundaryFeedbackDict)
- {
- if (null != MethodTag)
- if (item.Key(MethodTag)) item.Value(e);
- };
- });
- }
- #endregion
- #region 多点手势开始后
- private static ManipulationStartedEventHandler ElementManipulationStartedEventHandler()
- {
- return (sender, e) =>
- {
- if (null != ManipulationStartedDict)
- foreach (var item in ManipulationStartedDict)
- {
- if (null != MethodTag)
- if (item.Key(MethodTag)) item.Value(e);
- };
- };
- }
- #endregion
- #region 多点手势完成
- private static ManipulationCompletedEventHandler ElementManipulationCompletedEventHandler()
- {
- return (sender, e) =>
- {
- if (null != ManipulationCompletedDict)
- foreach (var item in ManipulationCompletedDict)
- {
- if (null != MethodTag)
- if (item.Key(MethodTag)) item.Value(e);
- };
- };
- }
- #endregion
- #region 多点手势惯性开始
- /// <summary>
- ///
- /// </summary>
- /// <param name="trans">10</param>
- /// <param name="scale">0.1</param>
- /// <param name="rotation">540</param>
- /// <returns></returns>
- private static ManipulationInertiaStartingEventHandler ElementManipulationInertiaStartingEventHandler(double trans, double scale, double rotation)
- {
- return (sender, e) =>
- {
- e.TranslationBehavior.DesiredDeceleration = trans * 96.0 / (1000.0 * 1000.0);
- e.ExpansionBehavior.DesiredDeceleration = scale * 96 / 1000.0 * 1000.0;
- e.RotationBehavior.DesiredDeceleration = rotation / (1000.0 * 1000.0);
- };
- }
- #endregion
- #endregion
- }
- }
xaml :
- <Page
- x:Class="MetroTimeline.MainPage"
- IsTabStop="false"
- xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
- xmlns:local="using:MetroTimeline"
- xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
- xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
- mc:Ignorable="d">
- <Canvas Background="{StaticResource ApplicationPageBackgroundThemeBrush}"
- Width="1080" Height="500"
- x:Name="cvsContent" Tag="default">
- <TextBlock Canvas.Left="573" TextWrapping="Wrap" Text="TextBlock" x:Name="tbInfo" ManipulationMode="All" Margin="219,597,171,10"/>
- <Image Source="Assets/PicWallLoading.jpg" ManipulationMode="All" Height="202" Canvas.Left="75" Canvas.Top="209" Width="153"/>
- <Image Source="Assets/PicWallLoading.jpg" ManipulationMode="All" Height="202" Canvas.Left="333" Canvas.Top="83" Width="153"/>
- </Canvas>
- </Page>
使用方式:
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Threading.Tasks;
- using Windows.Foundation;
- using Windows.Foundation.Collections;
- using Windows.UI.Xaml;
- using Windows.UI.Xaml.Controls;
- using Windows.UI.Xaml.Controls.Primitives;
- using Windows.UI.Xaml.Data;
- using Windows.UI.Xaml.Input;
- using Windows.UI.Xaml.Media;
- using Windows.UI.Xaml.Navigation;
- // The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238
- namespace MetroTimeline
- {
- /// <summary>
- /// An empty page that can be used on its own or navigated to within a Frame.
- /// </summary>
- public sealed partial class MainPage : Page
- {
- public MainPage()
- {
- this.InitializeComponent();
- var conRect = new Rect(Canvas.GetLeft(cvsContent), Canvas.GetTop(cvsContent),
- cvsContent.Width, cvsContent.Height);
- MetroManipulationHelper.InitManipulation(cvsContent, ManipulationModes.All, 5, 0.5, 360, conRect);
- MetroManipulationHelper.MethodTag = cvsContent.Tag.ToString();
- }
- /// <summary>
- /// Invoked when this page is about to be displayed in a Frame.
- /// </summary>
- /// <param name="e">Event data that describes how this page was reached. The Parameter
- /// property is typically used to configure the page.</param>
- protected override void OnNavigatedTo(NavigationEventArgs e)
- {
- }
- }
- }
conRect 为当前需要操作的容器 相对他父级容器的大小以及位置,用于判断多点元素的活动范围,
如果范围是全屏的话 则无需传该参数,进行相应修改即可
最后是效果图:

demo 下载地址:http://download.csdn.net/detail/wangrenzhu2011/4420853
windows8 开发教程 教你制作 多点触控Helper可将任意容器内任意对象进行多点缩放的更多相关文章
- 【朝花夕拾】Android自定义View篇之(八)多点触控(上)MotionEvent简介
前言 在前面的文章中,介绍了不少触摸相关的知识,但都是基于单点触控的,即一次只用一根手指.但是在实际使用App中,常常是多根手指同时操作,这就需要用到多点触控相关的知识了.多点触控是在Android2 ...
- [yueqian_scut]Android多点触控技术和应用框架
Android多点触控技术跟Linux输入子系统紧密相关.本文将从应用的角度说明Android多点触控技术的接口和应用. 一.多点触控场景分析 网络上有关Android多点触控技术的文章多见于两点拉伸 ...
- 【原】cocos2d-x开发笔记:多点触控
在项目开发中,我们做的大地图,一个手指头按下滑动可以拖动大地图,两个手指头按下张开或者闭合,可以放大和缩小地图 在实现这个功能的时候,需要使用到cocos2d-x的多点触控功能. 多点触控事件,并不是 ...
- Android开发实例之多点触控程序
智能终端设备的多点触控操作为我们带来了种种炫酷体验,这也使得很多Android开发者都对多点触控程序的开发感兴趣.实际上多点触控程序的实现并不是那么遥不可及,而是比较容易.本文就主要通过一个实例具体讲 ...
- Android多点触控技术,实现对图片的放大缩小平移,惯性滑动等功能
首先推荐一下鸿洋大大的打造个性的图片预览与多点触控视频教程,这套教程教我们一步一步实现了多点触控实现对图片的平移和缩放的功能.这篇文章我将在鸿洋大大的基础之上做了一些扩展功能: 1.图片的惯性滑动 2 ...
- Android多点触控技术实战,自由地对图片进行缩放和移动
转载请注明出处:http://blog.csdn.net/guolin_blog/article/details/11100327 在上一篇文章中我带着大家一起实现了Android瀑布流照片墙的效果, ...
- MSDN 杂志:UI 前沿技术 - WPF 中的多点触控操作事件
原文 MSDN 杂志:UI 前沿技术 - WPF 中的多点触控操作事件 UI 前沿技术 WPF 中的多点触控操作事件 Charles Petzold 下载代码示例 就在过去几年,多点触控还只是科幻电 ...
- (一)自定义ImageView,初步实现多点触控、自由缩放
真心佩服那些一直专注于技术共享的大神们,正是因为他们无私的分享精神,我才能每天都有进步.近日又算是仔细学了android的自定义控件技术,跟着大神的脚步实现了一个自定义的ImageView.里面涉及到 ...
- Appium+python自动化(二十九)- 模拟手指在手机上多线多点作战 - 多点触控(超详解)
简介 在网页中我们经常使用缩放操作来便利的查看具体的信息,在appium中使用MultiAction多点触控的类来实现.MultiAction是多点触控的类,可以模拟用户多点操作.主要包含加载add( ...
随机推荐
- hiho一下 第九十七周 数论六·模线性方程组
题目1 : 数论六·模线性方程组 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Ho:今天我听到一个挺有意思的故事! 小Hi:什么故事啊? 小Ho:说秦末,刘邦的将军 ...
- openstack 前期准备工作
OS 是 centos6.5_X86_64 一.vmware 虚拟机 准备两台机虚拟机即可 二.导入第三方安装源 [root@openstack ~]# rpm -Uvh http://dl.fedo ...
- shell脚本的调试技巧
请参考文章:http://www.ibm.com/developerworks/cn/linux/l-cn-shell-debug/index.html 读后的感觉,还是用shell的选项灵活,方便. ...
- pro git 使用积累
http://www.zhihu.com/question/20070065 git相关问题的收集 Git 是 Linux 之父 Linus Trovalds,为管理 Linux 内核代码而建立的,被 ...
- Maximum Gap
Given an unsorted array, find the maximum difference between the successive elements in its sorted f ...
- 【原创】Mapped Statements collection does not contain value for DaoImpl.method
问题: org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.Pers ...
- Apache配置文件中的deny和allow的使用
Apache配置文件中的deny和allow的使用 由于产品的需要,最近在配置apache的负载均衡功能,但是在配置虚拟主机的访问权限的时候我们遇到了一些问题.主要问题是deny和allow的执行顺序 ...
- maven web项目build失败
通过maven build发布web项目到tomcat时报如下异常: [INFO] ---------------------------------------------------------- ...
- mybatis There is no getter for property named 'xx' in 'class java.lang.String
转载自://http://www.cnblogs.com/anee/p/3324140.html 用mybatis查询时,传入一个字符串传参数,且进行判断时,会报 There is no getter ...
- php的socket通信(二)
案例一:代码详解 // 设置一些基本的变量$host = "192.168.1.99";$port = 1234;// 设置超时时间set_time_limit(0);// 创建一 ...