ActionScript 3 As3:多点触控缩放和旋转

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ActionScript 3 As3:多点触控缩放和旋转相关的知识,希望对你有一定的参考价值。

package
{
	import flash.display.Bitmap;
	import flash.display.Sprite;
	import flash.events.TransformGestureEvent;
	import flash.text.TextField;
	import flash.text.TextFormat;
	import flash.ui.Multitouch;
	import flash.ui.MultitouchInputMode;
	
	[SWF(width=320, height=460, frameRate=24, backgroundColor=0x000000)]
	public class GestureExample extends Sprite
	{
		[Embed(source="african_elephant.jpg")]
		public var ElephantImage:Class;
		public var scaleDebug:TextField;
		public var rotateDebug:TextField;

		public function GestureExample()
		{
			// Debug
			var tf:TextFormat = new TextFormat();
			tf.color = 0xffffff;
			tf.font = "Helvetica";
			tf.size = 11;
			this.scaleDebug = new TextField();
			this.scaleDebug.width = 310;
			this.scaleDebug.defaultTextFormat = tf;
			this.scaleDebug.x = 2;
			this.scaleDebug.y = 2;
			this.stage.addChild(this.scaleDebug);
			this.rotateDebug = new TextField();
			this.rotateDebug.width = 310;
			this.rotateDebug.defaultTextFormat = tf;
			this.rotateDebug.x = 2;
			this.rotateDebug.y = 15;
			this.stage.addChild(this.rotateDebug);

			var elephantBitmap:Bitmap = new ElephantImage();
			var elephant:Sprite = new Sprite();
			
			elephant.addChild(elephantBitmap);
			
			elephant.x = 160;
			elephant.y = 230;
			
			elephantBitmap.x = (300 - (elephantBitmap.bitmapData.width / 2)) * -1;
			elephantBitmap.y = (400 - (elephantBitmap.bitmapData.height / 2)) *-1;
			
			this.addChild(elephant);

			Multitouch.inputMode = MultitouchInputMode.GESTURE;
			elephant.addEventListener(TransformGestureEvent.GESTURE_ZOOM, onZoom);
			elephant.addEventListener(TransformGestureEvent.GESTURE_ROTATE, onRotate);
		}
		
		private function onZoom(e:TransformGestureEvent):void
		{
			this.scaleDebug.text = (e.scaleX + ", " + e.scaleY);
			var elephant:Sprite = e.target as Sprite;
			elephant.scaleX *= e.scaleX;
			elephant.scaleY *= e.scaleY;
		}
		
		private function onRotate(e:TransformGestureEvent):void
		{
			var elephant:Sprite = e.target as Sprite;
			this.rotateDebug.text = String(e.rotation);
			elephant.rotation += e.rotation;
		}
	}
}

以上是关于ActionScript 3 As3:多点触控缩放和旋转的主要内容,如果未能解决你的问题,请参考以下文章

所有子控件也随着缩放手势缩放layout多点触控layout

多点触控 地图缩放

Android多点触控技术,实现对图片的放大缩小平移,惯性滑动等功能

有人可以解释多点触控缩放是不是应该适用于 UITextView 或 UIScrollView

Android实现多点触控,自由缩放图片

IOS:仅使用多点触控缩放 uiscrollview