2012-02-22 41 views
0

我嘗試使用 transformGestureEvent.GESTURE_ZOOM對Android手機進行放大和縮小功能,但它沒有正確縮放,因爲它始終只在內容中的兩個手指之間縮放中心點(特定區)。Flex GestureZoom無法正常工作特定區域

我試過3個以下功能樣本放大和縮小

 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> 

那麼,什麼做錯了我的代碼。我如何縮放兩個手指之間的確切內容(特定區域)。如果有人知道,請讓我知道。

回答

1

TransformGestureEvent具有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。和當手勢開始設置這些VARS到當前localx/Y但工作任何想法...如果(event.phase == GesturePhase.END)\t { \t \t \t \t \t跟蹤( '結束' + oldlocalY); \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 2012-02-23 06:13:14

+0

感謝瓦倫丁:) – user1206485 2012-02-23 10:27:37

0

我知道了。當我嘗試縮放特定區域時,我使用了下面的代碼。它工作但不滾動。

Mtransform = swfLoader.content.transform.matrix; 
      Mtransform.translate(-originX, -originY); 
      Mtransform.scale(scale, scale); 
      Mtransform.translate(originX, originY); 
      swfLoader.content.transform.matrix = Mtransform;