我有一個容器內的Image
組件,其中clipAndEnableScrolling
屬性設置爲true。我需要一個靜態方法,它獲取這個Image
,旋轉角度並圍繞容器的中心點旋轉Image
,而不會丟失任何以前的轉換。我創建的最好的方法在幾次旋轉之後增加了錯誤。圍繞其容器的中心點旋轉圖像
我的事情,必須像這樣工作
public static function rotateImageAroundCenterOfViewPort(image:Image, value:int):void
{
// Calculate rotation and shifts
var bounds:Rectangle = image.getBounds(image.parent);
var angle:Number = value - image.rotation;
var radians:Number = angle * (Math.PI/180.0);
var shiftByX:Number = image.parent.width/2 - bounds.x;
var shiftByY:Number = image.parent.height/2 - bounds.y;
// Perform rotation
var matrix:Matrix = new Matrix();
matrix.translate(-shiftByX, -shiftByY);
matrix.rotate(radians);
matrix.translate(+shiftByX, +shiftByY);
matrix.concat(image.transform.matrix);
image.transform.matrix = matrix;
}
但事實並非如此。貌似我不明白轉型的工作原理(
不,我需要使它看起來像是圍繞容器中心旋轉。它比單純圍繞組件中心更復雜。 – Lingviston
噢好吧沒問題,我也會將其添加到我的答案中。 –