我有一层需要转换。目前,我正在使用以下内容:
self.customLayer.transform = CATransform3DRotate(CATransform3DIdentity,M_PI / 2.0f, 0, 0, 1);这正确地使图层正面朝上,但它也需要水平翻转,因为这是错误的方式。如何调整CATransform3DRotate才能做到这一点?
发布于 2012-04-28 06:29:12
您需要:
self.customLayer.transform = CATransform3DScale(CATransform3DMakeRotation(M_PI / 2.0f, 0, 0, 1),
-1, 1, 1);带-1的比例是翻转。想象一下,你正在水平挤压图像,并且超过了零。
发布于 2013-07-17 12:50:28
因为这里的参数是
CATransform3DScale (CATransform3D t, CGFloat sx, CGFloat sy, CGFloat sz)如果要水平翻转,则不应在CATransform3DMakeRotation()中提供任何向量值。相反,您只想控制x轴的比例。
通过水平翻转它,你应该:
self.transform = CATransform3DScale(CATransform3DMakeRotation(0, 0, 0, 0),
-1, 1, 1);如果要将其翻转回原点,请执行以下操作:
self.transform = CATransform3DScale(CATransform3DMakeRotation(0, 0, 0, 0),
1, 1, 1); 添加:
较短的版本将为您节省一次操作。要翻转:
self.transform = CATransform3DMakeRotation(M_PI, 0, 1, 0);要翻转回正常状态,请执行以下操作:
self.transform = CATransform3DMakeRotation(0, 0, 1, 0);发布于 2013-01-04 19:20:36
我个人发现使用KVC来做这些事情可读性更好。您可以使用类似以下内容来实现相同的效果:
// Rotate the layer 90 degrees to the left
[self.customLayer setValue:@-1.5707 forKeyPath:@"transform.rotation"];
// Flip the layer horizontally
[self.customLayer setValue:@-1 forKeyPath:@"transform.scale.x"];https://stackoverflow.com/questions/10358486
复制相似问题