views:

233

answers:

3

For example, I can access them like this:

self.layer.transform.m32

but I can't assign a value to it, like

self.layer.transform.m32 = 0.3f;

it says invalid assignment. But shouldn't that actually work?

struct CATransform3D
   {
   CGFloat m11, m12, m13, m14;
   CGFloat m21, m22, m23, m24;
   CGFloat m31, m32, m33, m34;
   CGFloat m41, m42, m43, m44;
};

at least Xcode does recognize all these fields in the matrix.

+3  A: 

You access property called "transform" (CALayer class) i.e. call setter function with CATransform3D argument type. Therefore you cannot access to CATransform3D structure members directly.

You may need to initialize temporary variable first (CATransform3D type) then assign it to property entirely.

Same thing will occur with any property you try to access this way.

For example:

view.frame.origin.x = 0; //will **not** work for UIView* view

Worked sample (via temporary variable):

CATransform3D temp = self.layer.transform; //create  temporary copy
temp.m32 = 0.3f; 
self.layer.transform = temp; //call setter [self.layer setTransform:temp]- mean the same
MikZ
A: 

I seem to have no trouble accessing and setting transforms this way;

CATransform3D t = view.transform;
NSLog(@"t.m32 = %f, t.m34 = %f", t.m32, t.m34);
t.m34 = 100.5;
NSLog(@"t.m32 = %f, t.m34 = %f", t.m32, t.m34);
view.transform = t;
mahboudz
A: 

self.layer.transform.m32 = 0.3f; won't do anything to the layer's transform.

self.layer.transform returns a CATransform3D, which is not an object. That means it is copied and if you change .m32 you're changing the copy, not the layer's CATransform3D.

This would work (similar to mahboudz' code sample):

CATransform3D t = self.layer.transform; // t is a copy of self.layer.transform
t.m32 = 0.3f; // modify the copy
self.layer.transform = t; // copy it back into self.layer.transform
Thomas Müller