不知道什麼這些xx
和xy
和所有其他類似的成員意味着什麼,但我的猜測*是,你將無法追溯僅使用這些值應用的轉換(它會像追溯1+2+3+4
只知道你從1
開始,最後是10
- 我想*)。
在這種情況下,我的建議是從CGAffineTransform
導出和存儲所需的值,但因爲它是一個結構,你不能這樣做,所以在我看來,你最好的選擇就是寫一個包裝類,像這樣:
class MyTransform
{
//wrapped transform structure
private CGAffineTransform transform;
//stored info about rotation
public float Rotation { get; private set; }
public MyTransform()
{
transform = CGAffineTransform.MakeIdentity();
Rotation = 0;
}
public void Rotate(float angle)
{
//rotate the actual transform
transform.Rotate(angle);
//store the info about rotation
Rotation += angle;
}
//lets You expose the wrapped transform more conveniently
public static implicit operator CGAffineTransform(MyTransform mt)
{
return mt.transform;
}
}
現在定義操作,您可以使用這個類是這樣的:
//do Your stuff
MyTransform t = new MyTransform();
t.Rotate(angle);
view.Transform = t;
//get the rotation
float r = t.Rotation;
//unfortunately You won't be able to do this:
float r2 = view.Transform.Rotation;
,你可以看到這種方法也有它的侷限性,但您可以隨時使用的MyTransform
只有一個實例應用所有這樣轉換rts並將該實例存儲在某處(或者可能是這種轉換的集合)。
您可能還需要存儲/揭露其他變換一樣規模或在MyTransform
類翻譯,但我相信你會知道在哪裏可以從這裏走。
* 隨時糾正我,如果我錯了
你的方法是堅實的,正是我會去了。但是如果任何人有任何光線照射在這個問題上自由! – LampShade 2013-02-10 20:09:43