【发布时间】:2010-08-25 11:36:09
【问题描述】:
如何通过将 CATransform3D 结构作为输入来计算绕 Z 轴的弧度旋转?
基本上我需要的是相反的CATransform3DMakeRotation。
【问题讨论】:
标签: iphone core-animation catransform3d
如何通过将 CATransform3D 结构作为输入来计算绕 Z 轴的弧度旋转?
基本上我需要的是相反的CATransform3DMakeRotation。
【问题讨论】:
标签: iphone core-animation catransform3d
这取决于您在哪个轴上进行旋转。
绕z轴的旋转表示为:
a = angle in radians
x' = x*cos.a - y*sin.a
y' = x*sin.a + y*cos.a
z' = z
( cos.a sin.a 0 0)
(-sin.a cos.a 0 0)
( 0 0 1 0)
( 0 0 0 1)
所以角度应该是a = atan2(transform.m12, transform.m11);
绕x轴旋转:
a = angle in radians
y' = y*cos.a - z*sin.a
z' = y*sin.a + z*cos.a
x' = x
(1 0 0 0)
(0 cos.a sin.a 0)
(0 -sin.a cos.a 0)
(0 0 0 1)
绕y轴旋转:
a = angle in radians
z' = z*cos.a - x*sin.a
x' = z*sin.a + x*cos.a
y' = y
(cos.a 0 -sin.a 0)
(0 1 0 0)
(sin.a 0 cos.a 0)
(0 0 0 1)
【讨论】:
如果将变换附加到图层,则可以如下获取旋转的值:
CGFloat angle = [(NSNumber *)[layer valueForKeyPath:@"transform.rotation.z"] floatValue];
Core Animation 扩展了键值编码协议,允许通过键路径获取和设置层的 CATransform3D 矩阵的公共值。表 4 描述了层的 transform 和 sublayerTransform 属性是键值编码和观察兼容的关键路径
【讨论】: