我有一个高度为50的图层,我围绕x轴旋转它。 。 。如何在旋转进行时计算高度?
CATransform3D subLayerTransform = CATransform3DMakeTranslation(0, 0, 0);
subLayerTransform.m34 = -1 / 1800; //How does height relate to perspective and angle?
subLayerTransform = CATransform3DTranslate(subLayerTransform, 0, 0, 0);
subLayerTransform = CATransform3DRotate(subLayerTransform, 45 * (M_PI / 180), 1, 0, 0);
_transitionLayer.sublayerTransform = subLayerTransform;
答案 0 :(得分:3)
围绕y轴旋转
高度为y1 - y0。因此,计算新的y1和y0:
CGFloat y0 = 0;
CGFloat y1 = 50;
CGFloat z = -1800; //This relates to the m34 perspective matrix.
y0 = y0 * cos(radians(45)) - z * sin(radians(45));
y1 = y1 * cos(radians(45)) - z * sin(radians(45));
CGFloat newHeight = y1 - y0;