【问题标题】:Flex GestureZoom not working properly specific areaFlex GestureZoom 在特定区域无法正常工作
【发布时间】:2012-02-22 13:10:17
【问题描述】:

我尝试了 android 手机的放大和缩小功能,通过使用 transformGestureEvent.GESTURE_ZOOM 但它不能正确缩放,因为它总是缩放中心点,只是在内容(特定区域)内的两个手指之间不精确。

我尝试了以下 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>

那么我的代码出了什么问题。我如何在两根手指之间缩放精确的内容(特定区域)。如果有人知道,请告诉我。

【问题讨论】:

    标签: android actionscript-3 apache-flex flex4.5


    【解决方案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;
    

    【讨论】:

    • 仍然无法正常工作。我尝试在手势阶段结束时保留 localx 和 oldlocaly。并且当手势开始时,将这些变量设置为当前的 localx/y,但有任何想法... if(event.phase == GesturePhase.END) { trace('End'+oldlocalY); oldlocalX = event.localX; oldlocalY = event.localY; }
    【解决方案2】:

    我明白了。当我尝试缩放特定区域时,我为此使用了以下代码。它工作但不滚动。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-04-02
      • 2015-07-11
      • 1970-01-01
      • 2013-10-07
      • 1970-01-01
      • 1970-01-01
      • 2011-03-31
      相关资源
      最近更新 更多