3D立方体问题!第1部分 [英] 3D Cube Problem! Part 1
问题描述
我已经使用 CALayer的
在iPhone中创建了3D立方体。现在我想在用户双击时以90˚
的角度旋转该多维数据集( CALayer
)。
I have created a 3D cube in iphone using CALayer's
. Now I wanted to rotate that cube(CALayer
) at 90˚
when user double taps on it.
我能够将那个多维数据集( CALayer
)旋转到90˚
一次,但是当我双击多维数据集( CALayer
)没有旋转时。
I was able to rotate that cube(CALayer
) to 90˚
once but when I double tap the cube(CALayer
) is not rotating.
这是我使用的代码旋转立方体( CALayer
)
Here is the code that I used to rotate the cube(CALayer
)
CATransform3D x = CATransform3DRotate(currentLayer.sublayerTransform, M_PI / 2, 0, 0, 1);
currentLayer.transform = x;
任何人都可以帮忙。我做错了。
Can anyone help in this. What I'm doing wrong.
PS。对于想知道我如何获得学位的人来说,这就是窍门
PS. For the people who are wondering how I got the degree sign then here is the trick
选项 + K
推荐答案
它是因为您没有更改旋转角度....要理解这一点,可以说您正在传递每个M_PI / 2该方法的时间....因此, CATransform3DRotate
不要将其旋转到 next90˚
,而是将图层旋转到指定的角度在这种情况下为90 ...因此您不会遇到任何障碍,因为它已经在90˚
......为了获得正确的结果,请执行此操作
its because you are not changing the angle of rotation .... to understand this lets say you are passing M_PI/2 each time to that method .... so CATransform3DRotate
do not rotate it to next 90˚
rather it rotate the layer to the specified angle in this case its 90... so you are not getting any chage because it already at 90˚
..... so to get correct result do this
static float angle = M_PI / 2;//dont make it static rather make it a global variable
angle += M_PI / 2;
CATransform3D x = CATransform3DRotate(currentLayer.sublayerTransform,angle, 0, 0, 1);
currentLayer.transform = x;
这篇关于3D立方体问题!第1部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!