0

在此代码画布中,id layout_cnv 对齐水平居中对齐和垂直居中对齐。当图像放大时,它正在缩放但不是从顶部和左侧显示,它正在进入内部意味着它不是从左侧和顶部位置滚动

我想在中心位置而不是从左上角放大。

请帮我

<mx:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
           xmlns:mx="library://ns.adobe.com/flex/mx"
           xmlns:s="library://ns.adobe.com/flex/spark">
<fx:Script>
    <![CDATA[
        import mx.events.SliderEvent;

        private function changeZoom(event:SliderEvent) : void
        {
            layout_cnv.scaleX = event.target.values[0]*2/100;
            layout_cnv.scaleY = event.target.values[0]*2/100;
        }           

        private function calculateCoordinates() : void
        {
            var x : Number = (canvas.width - layout_cnv.width) / 2;

            x = x < 0 ? 0 : x;
            var y : Number = (canvas.height - layout_cnv.height) / 2;
            y = y < 0 ? 0 : y;

            layout_cnv.move(x, y);  

            callLater(calculateCoordinates);
        }

        private function adjustDefaultZoom() : void
        {
            layout_cnv.scaleX = slider.values[0]/100*2;
            layout_cnv.scaleY = slider.values[0]/100*2;
            callLater(calculateCoordinates);
        }

        private function myDataTipFunc(val:String):String {
            return  String(val)+ "%";
        }
    ]]>
</fx:Script>

<mx:Panel title="Zoom Demo" width="100%" height="100%">     
    <mx:Canvas id="canvas" width="100%" height="100%"  horizontalScrollPosition="500">          
        <mx:Canvas visible="true" id="layout_cnv" creationComplete="adjustDefaultZoom()"  borderStyle="solid" height="300" width="500" verticalCenter="0" horizontalCenter="0"
                   verticalScrollPolicy="off" horizontalScrollPolicy="off" backgroundColor="#FFFFFF">           
            <mx:Image id="swfContainer" source="thumbImages/1.jpg"  x="0" y="0" width="100%" height="100%"/>        
        </mx:Canvas>
    </mx:Canvas>

    <mx:ControlBar horizontalAlign="center">
        <mx:HSlider id="slider" width="400" minimum="1" maximum="100" labels="['0%','100%']" values="[50]" tickInterval="10" snapInterval="1" liveDragging="true" change="changeZoom(event)"
                    dataTipFormatFunction="myDataTipFunc" />
    </mx:ControlBar>        
</mx:Panel>

谢谢,尼丁

4

0 回答 0