2012-02-22 47 views
0

transformGestureEvent.GESTURE_ZOOMを使用してAndroidのズームイン/アウト機能を試しましたが、コンテンツ内の2本の指の間に常に正確なズーミングの中心点しかないため、エリア)。Flex GestureZoomが正しく動作しない特定の領域

私は、だから何が私のコードで間違っていた

内外
 1. private function onZoom(e:TransformGestureEvent):void/* not working properly */ 
     { 
      swfLoader.scaleX *= e.scaleX; 
      swfLoader.scaleY *= e.scaleY; 
     } 
     2. private function onZoom(e:TransformGestureEvent):void/* not working properly */ 
     { 
      swfLoader.scaleX *= (e.scaleX+e.scaleY)/2; 
      swfLoader.scaleY *= (e.scaleX+e.scaleY)/2; 
     }3. private function onZoom(e:TransformGestureEvent):void 
     { 
      // scale the view 
      swfLoader.scaleX *= e.scaleX; 
      swfLoader.scaleY *= e.scaleY; 

      var bounds2:Rectangle = swfLoader.content.getBounds(swfLoader.stage); 
      var dx:Number = bounds2.x - bounds1.x; 
      var dy:Number = bounds2.y - bounds1.y; 
      var dw:Number = bounds2.width - bounds1.width; 
      var dh:Number = bounds2.height - bounds1.height; 

      // move the view to keep it centered while zooming 
      swfLoader.x -= dx + dw/2; 
      swfLoader.y -= dy + dh/2; 

     }<s:BorderContainer id="contentPanel" width="100%" height="100%" backgroundColor="#cccccc" > 
    <s:Scroller id="scroller" width="100%" height="100%" > 
       <s:VGroup id="swfloadergroup" width="100%" height="100%" horizontalAlign="center" verticalAlign="middle" > 

       <s:SWFLoader id="swfLoader" smoothBitmapContent="true" autoLoad="true" doubleClickEnabled="true" 
          maintainAspectRatio="true" gestureZoom="onZoom(event)" scaleContent="true" loadForCompatibility="true" /> 

       <s:SWFLoader id="preLLoader" autoLoad="true" width="30%" height="30%" 
          source="@Embed('assets/loading.swf')" 
          maintainAspectRatio="true" scaleContent="true "/> 
       </s:VGroup> 

    </s:Scroller> 
</s:BorderContainer> 

をズームための3以下の機能のサンプルを試してみました。私はどのように2つの指の間の正確な内容(特定の領域)をズームすることができます。もし誰か知っていれば教えてください。

答えて

1

TransformGestureEventは、2本の指の間の中心のコリネートを含むlocalXlocalYのプロパティを持ちます。

非中心点からオブジェクトを移動せずにズームすることはできませんが、ズームジェスチャだけでは、「固定」のオブジェクトも移動できます。ジェスチャを自然に見えるようにするには、スプライトを位置の違いで移動し、特定の点からズームする必要があります。

古い座標を保持するには、oldLocalXoldLocalYが必要です。 gesture.phase == GesturePhase.BEGINの場合、これらの変数を現在のlocalX/localYに設定します。その後、新しいデルタであなたのスプライトを移動します。特定のポイントからオブジェクトをズームする

は、次の手順を実行します。

var matrix:Matrix = this.transform.matrix; 
matrix.translate(-event.localX, -event.localY); 
matrix.scale(event.scaleX, event.scaleY); 
matrix.translate(event.localX, event.localY); 
this.transform.matrix = matrix; 
+0

まだ正しく動作していません。ジェスチャフェーズが終了すると、localxとoldlocalyを保持しようとしました。そして、ジェスチャーは、現在のlocalXプロパティ/ Yが、任意のアイデアを働いて...もし(event.phase == GesturePhase.END)\t { \t \t \t \t \tトレース( '終了' + oldlocalY)にこれらのVARS設定し始めると、を \t \t \t \t \t \t \t \t \t \t oldlocalX = event.localXを。 \t \t \t \t \t oldlocalY = event.localY; \t \t \t \t \t \t \t \t \t} – user1206485

+0

おかげバレン:) – user1206485

0

私はそれを得ました。私はズームの特定の領域にしようとしたとき、私はこれのために以下のコードを使用しました。それは動作していますが、スクロールしていません。

Mtransform = swfLoader.content.transform.matrix; 
      Mtransform.translate(-originX, -originY); 
      Mtransform.scale(scale, scale); 
      Mtransform.translate(originX, originY); 
      swfLoader.content.transform.matrix = Mtransform; 
関連する問題