如何更改变换的值?
例如,我可以像这样访问它们:
self.layer.transform.m32
但我无法为其分配值,就像
self.layer.transform.m32 = 0.3f;
它说无效分配一样。 但这实际上不应该起作用吗?
struct CATransform3D
{
CGFloat m11, m12, m13, m14;
CGFloat m21, m22, m23, m24;
CGFloat m31, m32, m33, m34;
CGFloat m41, m42, m43, m44;
};
至少 Xcode 确实能够识别矩阵中的所有这些字段。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您访问名为“transform”的属性(CALayer 类),即使用 CATransform3D 参数类型调用 setter 函数。
因此您无法直接访问 CATransform3D 结构成员。
您可能需要先初始化临时变量(CATransform3D 类型),然后将其完全分配给属性。
您尝试以这种方式访问的任何属性都会发生同样的情况。
例如:
工作示例(通过临时变量):
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:
Worked sample (via temporary variable):
我似乎以这种方式访问和设置转换没有问题;
I seem to have no trouble accessing and setting transforms this way;
self.layer.transform.m32 = 0.3f;
不会对图层的变换执行任何操作。self.layer.transform 返回一个 CATransform3D,它不是一个对象。 这意味着它被复制,如果您更改
.m32
,您将更改副本,而不是图层的 CATransform3D。这可行(类似于 mahboudz 的代码示例):
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):