CALayer

CALayer

1.3D变换中的透视效果,由矩阵中的m34元素控制,用于按比例缩放x、y,以此计算离视角有多远。m34默认值是0,通过设置 m34 = -1.0 / d 来应用透视效果,d代表视角相机与屏幕的距离,单位是像素,其值一般为 500 ~ 1000
例如旋转一个3D方块,使其呈现透视效果。

- (void)pan:(UIPanGestureRecognizer *)g {
CGPoint p = [g translationInView:self.view];

CATransform3D transform = CATransform3DIdentity;
transform.m34 = -1.0 / 2000;

transform = CATransform3DRotate(transform, 0.01 * p.x, 0, 1, 0); // x 值变化是随着y轴旋转
transform = CATransform3DRotate(transform, -0.01 * p.y, 1, 0, 0); // y 值变化是随着x轴旋转

self.view.layer.sublayerTransform = transform;
}

 
原文地址:https://www.cnblogs.com/buakaw/p/5725682.html