3D Cube Problem! Part 1

廉价感情. 提交于 2019-12-06 07:33:28

问题


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.

I was able to rotate that cube(CALayer) to 90˚ once but when I double tap the cube(CALayer) is not rotating.

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. For the people who are wondering how I got the degree sign then here is the trick

Option + K


回答1:


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;


来源:https://stackoverflow.com/questions/6275672/3d-cube-problem-part-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!