2015-02-23 113 views
0

我需要创建一个3D旋转框(立方体)使用objective-c我已经通过了几个教程,但不知道如何去与他们正确地得到像这个..我需要创建一个3D旋转框在objective-c

https://www.dropbox.com/s/1zjbglmveg02364/cover17.zip?dl=0

有人能指导如何使用的CALayer或UIView的与CATransform3DRotate & CATransform3DTranslate实现这一目标?

+0

有SceneKit它可以让你加载3D对象和旋转它们。这里有一个教程:http://www.ioscreator.com/tutorials/scene-kit-primitives-tutorial-swift – Zhang 2015-02-23 04:23:47

+0

我已经检查过,但我无法弄清楚是否有一些方法可以在立方体的面上添加文本。 – ayna 2015-02-23 04:42:02

+0

只需将文本作为纹理添加到您的多维数据集? (这导致第二个问题)。 – Zhang 2015-02-23 04:56:49

回答

2

四个面对立方体:

CATransform3D pt = CATransform3DIdentity; 
pt.m34 = -1.0/500.0; 
self.containerView.layer.sublayerTransform = pt; 

_cubeLayer = [CATransformLayer layer]; 

CALayer *face1 = [CALayer layer]; 
face1.backgroundColor = [UIColor redColor].CGColor; 
face1.frame = CGRectMake(0, 0, 100, 100); 
face1.transform = CATransform3DTranslate(face1.transform, 0, 0, 50); 
[_cubeLayer addSublayer:face1]; 

CALayer *face2 = [CALayer layer]; 
face2.backgroundColor = [UIColor greenColor].CGColor; 
face2.frame = CGRectMake(0, 0, 100, 100); 
face2.transform = CATransform3DTranslate(face2.transform, 0, 50, 0); 
face2.transform = CATransform3DRotate(face2.transform, M_PI/2, 1, 0, 0); 
[_cubeLayer addSublayer:face2]; 

CALayer *face3 = [CALayer layer]; 
face3.backgroundColor = [UIColor yellowColor].CGColor; 
face3.frame = CGRectMake(0, 0, 100, 100); 
face3.transform = CATransform3DTranslate(face3.transform, 0, -50, 0); 
face3.transform = CATransform3DRotate(face3.transform, M_PI/2, 1, 0, 0); 
[_cubeLayer addSublayer:face3]; 

CALayer *face4 = [CALayer layer]; 
face4.backgroundColor = [UIColor blueColor].CGColor; 
face4.frame = CGRectMake(0, 0, 100, 100); 
face4.transform = CATransform3DTranslate(face4.transform, 0, 0, -50); 
[_cubeLayer addSublayer:face4]; 


_cubeLayer.frame = CGRectMake(0, 0, 100, 100); 

[self.containerView.layer addSublayer:_cubeLayer]; 

旋转:

self.cubeLayer.transform = CATransform3DRotate(_cubeLayer.transform, M_PI/2, 1, 0, 0); 

结果: enter image description here

+0

我们如何添加左右脸? – Kemo 2016-09-26 18:49:13