了解CATransform3D

Die*_*res 6 uiview catransform3d quartz-core

我在UIView中玩CATransform3DMakeRotation,而我正试图做45º,变换就像它倒退一样:

http://cl.ly/2A2p1W1e2N3a1W181r35

这是我的"代码",但显然没有这样做.

CATransform3D _tr = CATransform3DMakeRotation(3.14/4, 1, 0, 0);
view.layer.transform = _tr;
Run Code Online (Sandbox Code Playgroud)

请帮我理解params.谢谢.

omz*_*omz 4

基本上,您的代码是正确的,但是为了获得透视效果,您需要将sublayerTransform超级视图的图层设置为如下所示:

CATransform3D perspectiveTransform = CATransform3DIdentity;
perspectiveTransform.m34 = 1.0 / -850;
myView.layer.sublayerTransform = perspectiveTransform;
Run Code Online (Sandbox Code Playgroud)

您可以针对不同的失真量尝试不同的值。

  • 你能解释一下你在那里做什么吗?我想学习,而不仅仅是复制粘贴和调整值。 (7认同)
  • 对于后代,Apple 在这里解释了 .m34 和 850 的含义:https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/CoreAnimation_guide/AdvancedAnimationTricks/AdvancedAnimationTricks.html#//apple_ref/doc/uid/ TP40004514-CH8-SW13 (3认同)