c# - Get angle of rotation after rotating a view -



c# - Get angle of rotation after rotating a view -

let's rotate view using next method:

cgaffinetransform t = cgaffinetransform.makeidentity(); t.rotate (angle); cgaffinetransform transforms = t; view.transform = transforms;

how can current rotation angle of view without keeping track of set in angle variable when did cgaffinetransform? related view.transform.xx/view.transform.xy values?

not sure these xx , xy , other similar members mean exactly, guess* won't able trace applied transformations using solely values (it tracing 1+2+3+4 knowing started off 1 , ended 10 - i think*).

in case suggestion derive cgaffinetransform , store desired values, since it's construction cannot that, in sentiment best selection write wrapper class, so:

class mytransform { //wrapped transform construction private cgaffinetransform transform; //stored info rotation public float rotation { get; private set; } public mytransform() { transform = cgaffinetransform.makeidentity(); rotation = 0; } public void rotate(float angle) { //rotate actual transform transform.rotate(angle); //store info rotation rotation += angle; } //lets expose wrapped transform more conveniently public static implicit operator cgaffinetransform(mytransform mt) { homecoming mt.transform; } }

now defined operator lets utilize class this:

//do stuff mytransform t = new mytransform(); t.rotate(angle); view.transform = t; //get rotation float r = t.rotation; //unfortunately won't able this: float r2 = view.transform.rotation;

as can see approach has it's limitations, can utilize 1 instance of mytransform apply sorts of transformations , store instance somewhere (or, possibly, collection of such transforms).

you may want store/expose other transformations scale or translate in mytransform class, believe you'll know go here.

*feel free right me if i'm wrong

c# monotouch rotation cgaffinetransform

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -