0

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.

4

3 回答 3

4

您可以访问名为“transform”(CALayer 类)的属性,即使用 CATransform3D 参数类型调用 setter 函数。因此,您不能直接访问 CATransform3D 结构成员。

您可能需要先初始化临时变量(CATransform3D 类型),然后将其完全分配给属性。

您尝试以这种方式访问​​的任何属性都会发生同样的事情。

例如:

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

工作样本(通过临时变量):

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
于 2009-07-24T23:47:38.853 回答
0

以这种方式访问​​和设置转换似乎没有问题;

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;
于 2009-11-04T05:50:24.900 回答
0

self.layer.transform.m32 = 0.3f;不会对图层的变换做任何事情。

self.layer.transform返回一个 CATransform3D,它不是一个对象。这意味着它被复制了,如果你改变.m32了,你改变的是副本,而不是图层的 CATransform3D。

这会起作用(类似于 mahboudz 的代码示例):

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
于 2009-11-04T06:04:06.183 回答